jnr / jffi

Java Foreign Function Interface
Apache License 2.0
168 stars 78 forks source link

Ability to log uncaught exceptions in closures? #41

Open ahilananantha opened 7 years ago

ahilananantha commented 7 years ago

Would be nice to be able to either register a callback for uncaught exceptions or toggle on/off calls to ExceptionDescribe when calling into Java functions from C. You call these closures? To clarify I mean uncaught exceptions from the jnr-ffi's "@Delegate" methods.

headius commented 7 years ago

Seems like a fair idea, but I think this would be a jnr-ffi change, yes? jffi is just the lowest levels. If you have an idea for how to implement this, we would welcome and work with you on a PR.

ahilananantha commented 7 years ago

I think it would need to be both jffi and jnr-ffi changes the way I'm thinking about it. It's in that C code in jffi where the exception is simply cleared. I'm thinking it's fastest to conditionally check for and handle the exception if some handler is registered at that very point. In jnr-ffi since it's all Java I'm not sure what you could do upon delegation completion that wouldn't slow everything down for people that were super careful to not throw exceptions?