On 30/03/2015 14:51, Bruno Albuquerque wrote:
I was checking the exceptions handling code for the C bindings and it looks
like it simply exists when an error happens.
For my purposes, it would be better if I could somehow trap errors and act
upon them instead of simply exiting. Is there a way to do it at all? I
noticed there is an Err_trap function in Clownfish but I am not sure if
that would do what I want or even how to use it.
Yes, the Err_trap function is what you want to use. It takes a function
pointer and a void pointer to a user context and executes the function. If a
Clownfish error is thrown, it is returned. Example:
static void
try_something(void *context) {
/* Execute code that might throw. */
}
void
other_code() {
Err *error = Err_trap(try_something, context);
if (error != NULL) {
/* Handle error. */
}
}
The problem with this approach is that it's based on setjmp/longjmp and can
leak memory, so our goal is to throw errors only in fatal situations. What's
your use case? If it's something common, we might consider an API change.
Nick