#include "akerror.h" #include "err_capture.h" /* * FINISH(ctx, false) closes an ATTEMPT block without propagating: an unhandled * error is dropped (not returned, not passed to the unhandled handler) and the * context is released back to the pool. Because we use FINISH (not * FINISH_NORETURN) the process must continue normally and exit 0. */ static int wrong_handler_fired = 0; static int swallowed_status = 0; akerr_ErrorContext *boom(void) { PREPARE_ERROR(e); FAIL_RETURN(e, AKERR_VALUE, "unhandled but swallowed"); } /* FINISH(e, false) belongs in a context-returning function. On the swallow * path e is released to NULL, so this returns NULL to its caller. */ akerr_ErrorContext *swallow_it(void) { PREPARE_ERROR(e); ATTEMPT { CATCH(e, boom()); } CLEANUP { swallowed_status = (e != NULL) ? e->status : 0; } PROCESS(e) { } HANDLE(e, AKERR_KEY) { wrong_handler_fired = 1; /* does not match AKERR_VALUE */ } FINISH(e, false); return e; /* NULL: released even though unhandled */ } int main(void) { akerr_capture_install(); akerr_ErrorContext *res = swallow_it(); AKERR_CHECK(wrong_handler_fired == 0); AKERR_CHECK(swallowed_status == AKERR_VALUE); AKERR_CHECK(res == NULL); /* released even though unhandled */ AKERR_CHECK(akerr_slots_in_use() == 0); fprintf(stderr, "err_swallow ok\n"); return 0; }