-
Notifications
You must be signed in to change notification settings - Fork 0
/
except_test.c
68 lines (54 loc) · 1.22 KB
/
except_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "util.h"
// This enum would normally exist in the application. The first value does
// not really matter, but it has to be higher than the highest one that is
// used in the library.
typedef enum {
// exception number zero is invalid
EXCEPT_ONE = 100,
EXCEPT_TWO,
EXCEPT_THREE,
EXCEPT_FOUR,
} exceptions;
void func4() {
printf("before raising 0x8080\n");
RAISE(0x8080, "this is exception 8080");
printf("after raising 0x8080\n");
}
void func3() {
printf("before calling 4\n");
func4();
printf("after calling 4\n");
}
void func2() {
TRY {
printf("before calling 3\n");
func3();
printf("after calling 3\n");
}
EXCEPT(EXCEPT_THREE) {
printf("exception number %d is not expected\n", EXCEPTION_NUM);
exit(1);
}
FINAL
}
void func1() {
printf("before calling 2\n");
func2();
printf("after calling 2\n");
}
int main() {
TRY {
func1();
}
EXCEPT(EXCEPT_TWO) {
printf("exception: %s\n", EXCEPTION_MSG);
}
/*
ANY_EXCEPT() {
printf("exception: 0x%04X: %s\n", EXCEPTION_NUM, EXCEPTION_MSG);
}
*/
FINAL
printf("main() is about to exit.\n");
return 0;
}