#include "akerror.h" #include "err_capture.h" /* * The unhandled-error hook (akerr_handler_unhandled_error) is overridable. * Install a non-fatal handler so an unhandled error can be asserted directly * (status, invocation) instead of relying on process death / WILL_FAIL. */ static int custom_fired = 0; static int custom_status = 0; static void my_handler(akerr_ErrorContext *e) { custom_fired = 1; custom_status = (e != NULL) ? e->status : -1; /* deliberately does NOT exit() */ } akerr_ErrorContext *boom(void) { PREPARE_ERROR(e); FAIL_RETURN(e, AKERR_TYPE, "unhandled on purpose"); } int main(void) { akerr_capture_install(); akerr_init(); /* sets the default handler... */ akerr_handler_unhandled_error = &my_handler; /* ...which we then override */ PREPARE_ERROR(e); ATTEMPT { CATCH(e, boom()); } CLEANUP { } PROCESS(e) { /* no HANDLE for AKERR_TYPE -> stays unhandled */ } FINISH_NORETURN(e); AKERR_CHECK(custom_fired == 1); AKERR_CHECK(custom_status == AKERR_TYPE); AKERR_CHECK_CONTAINS("Unhandled Error"); fprintf(stderr, "err_custom_handler ok\n"); return 0; }