You want to handle fatal errors (assertions) yourself rather than have the library call abort().
When there is an assertion failure, the library first checks whether the user has defined his/her own assertion handling mechanism. If not, it prints a message and calls abort. This is the default behaviour. But you can override this in the following way using the C API:
Define a function with the following signature:
typedef void (*codes_assertion_failed_proc)(const char* message); |
Then point the library to your function:
codes_set_codes_assertion_failed_proc(&your_function); |
To restore the default behaviour, call
codes_set_codes_assertion_failed_proc(NULL); |
static void my_assertion_proc(const char* message) { printf("It's OK. I caught the assertion: %s\n", message); // Do something like throw MyProj::FatalException(message); } int main(int argc, char **argv) { codes_set_codes_assertion_failed_proc(&my_assertion_proc); // All asserts in the ecCodes library will now be caught ... // Now restore default behaviour codes_set_codes_assertion_failed_proc(NULL); return 0; } |
Related articles appear here based on the labels you select. Click to edit the macro and add or change labels.
|