57 lines
1.3 KiB
C
57 lines
1.3 KiB
C
|
|
#include "akerror.h"
|
||
|
|
#include "err_capture.h"
|
||
|
|
|
||
|
|
/*
|
||
|
|
* HANDLE_GROUP lets several status codes share one handler body via
|
||
|
|
* case-fallthrough. The first member of the group uses HANDLE (which emits the
|
||
|
|
* leading break that terminates the previous case); each additional member
|
||
|
|
* uses HANDLE_GROUP; the shared body follows the last member. Verify that two
|
||
|
|
* different status codes both reach the shared body.
|
||
|
|
*/
|
||
|
|
|
||
|
|
static int group_fired = 0;
|
||
|
|
static int other_fired = 0;
|
||
|
|
|
||
|
|
akerr_ErrorContext *boom(int status)
|
||
|
|
{
|
||
|
|
PREPARE_ERROR(e);
|
||
|
|
FAIL_RETURN(e, status, "boom %d", status);
|
||
|
|
}
|
||
|
|
|
||
|
|
akerr_ErrorContext *run(int status)
|
||
|
|
{
|
||
|
|
PREPARE_ERROR(e);
|
||
|
|
ATTEMPT {
|
||
|
|
CATCH(e, boom(status));
|
||
|
|
} CLEANUP {
|
||
|
|
} PROCESS(e) {
|
||
|
|
} HANDLE(e, AKERR_KEY)
|
||
|
|
HANDLE_GROUP(e, AKERR_INDEX) {
|
||
|
|
group_fired++;
|
||
|
|
} HANDLE(e, AKERR_IO) {
|
||
|
|
other_fired++;
|
||
|
|
} FINISH(e, false);
|
||
|
|
return e;
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(void)
|
||
|
|
{
|
||
|
|
akerr_capture_install();
|
||
|
|
|
||
|
|
run(AKERR_KEY);
|
||
|
|
AKERR_CHECK(group_fired == 1);
|
||
|
|
AKERR_CHECK(other_fired == 0);
|
||
|
|
|
||
|
|
run(AKERR_INDEX);
|
||
|
|
AKERR_CHECK(group_fired == 2);
|
||
|
|
AKERR_CHECK(other_fired == 0);
|
||
|
|
|
||
|
|
run(AKERR_IO);
|
||
|
|
AKERR_CHECK(group_fired == 2);
|
||
|
|
AKERR_CHECK(other_fired == 1);
|
||
|
|
|
||
|
|
AKERR_CHECK(akerr_slots_in_use() == 0);
|
||
|
|
fprintf(stderr, "err_handle_group ok\n");
|
||
|
|
return 0;
|
||
|
|
}
|