You want to handle fatal errors (assertions) yourself rather than have the library call abort()
Step-by-step guide
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 can be done via is the default behaviour. But you can override this in the following way using the C API:
Define a function with the following signature:
Code Block |
---|
|
typedef void (*codes_assertion_failed_proc)(const char* message); |
Then call
Code Block |
---|
|
codes_set_codes_assertion_failed_proc(&your_function); |
- Now the library will call the chosen function (which for example could do nothing or throw a C++ exception) instead of the abort.
To restore the default behaviour, call
Code Block |
---|
|
codes_set_codes_assertion_failed_proc(NULL); |
- xx
Example
Code Block |
---|
|
static void my_assertion_proc(const char* message)
{
printf("It's OK. I caught the assertion: %s\n", message);
// Do something else
}
codes_set_codes_assertion_failed_proc(&my_assertion_proc);
// Do lots of experimental stuff knowing all asserts will be caught
// Now restore default behaviour
codes_set_codes_assertion_failed_proc(NULL); |
info |
Related articles
Content by Label |
---|
showLabels | false |
---|
max | 5 |
---|
spaces | UDOC |
---|
showSpace | false |
---|
sort | modified |
---|
reverse | true |
---|
type | page |
---|
cql | label in ("eccodes-faqs","kb-how-to-article") and type = "page" and space = "UDOC" |
---|
labels | kb-how-to-article eccodes-faqs |
---|
|
...