Uncaught exception when throwing within with_libc lambda

Christian Helmuth christian.helmuth at genode-labs.com
Mon Mar 30 15:07:46 CEST 2020


Hello Sid,

we already discussed this topic briefly in March 2017 [1]. Back then
(and still today), I'd suggest to implement the scheme you like but do
not depend on with_libc() or any RPC to transparently handle custom
exceptions. I never dived deeper into making with_libc() more
user-friendly because, frankly, it has never been a common use case to
implement complext libc-based components with custom exceptions.

[1] Exceptions in with_libc not working
    https://lists.genode.org/pipermail/users/2017-March/005087.html

Regards
-- 
Christian Helmuth
Genode Labs

https://www.genode-labs.com/ · https://genode.org/
https://twitter.com/GenodeLabs · /ˈdʒiː.nəʊd/

Genode Labs GmbH · Amtsgericht Dresden · HRB 28424 · Sitz Dresden
Geschäftsführer: Dr.-Ing. Norman Feske, Christian Helmuth

On Mon, Mar 30, 2020 at 14:21:57 CEST, Sid Hussmann wrote:
> I just stumbled across a not so obvious characteristic of the with_libc lambda. Not so obvious to me, at least.
> If I run following code snipped, it will result in a "Error: Uncaught exception of type 'Genode::Exception'":
> 
> 
> ``` 
> try {
> 	Libc::with_libc([&] () {
> 		throw Genode::Exception();
> 	});
> } catch (...) {
> 	Genode::log("caught libc exception");
> }
> ```
> 
> I didn't find any documentation regarding the with_libc lambda in combination with exceptions.
> Is this expected behavior?
> What would be the right pattern to forward the exception to a pure Genode environment e.g. across RPC boundaries?
> I could think of following pattern:
> 
> 
> ``` 
> bool libc_exception_thrown = false;
> Libc::with_libc([&] () {
> 	try {
> 		throw Genode::Exception();
> 	} catch (...) {
> 		Genode::log("caught libc exception");
> 		libc_exception_thrown = true;
> 	}
> });
> if (libc_exception_thrown) {
> 	throw My_rpc_exception();
> }
> ``` 
> 
> However, it does not look like the most elegant solution...
> 
> Cheers,
> Sid



More information about the users mailing list