Uncaught exception when throwing within with_libc lambda

Sid Hussmann sid.hussmann at gapfruit.com
Mon Mar 30 14:21:57 CEST 2020


Dear Genodians,

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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.genode.org/pipermail/users/attachments/20200330/ba4d1926/attachment.sig>


More information about the users mailing list