-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
88 lines (79 loc) · 1.26 KB
/
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include"try-catch.h"
#include<stdio.h>
#define CODE_1 1
#define CODE_2 2
#define CODE_3 3
exception_t e;
int test1() {
int a[] = {CODE_1, CODE_2, CODE_3};
try_catch(&e, a, 3);
try_catch_end(&e);
return 0;
}
int test2() {
int a[] = {CODE_1, CODE_2, CODE_3};
int val = try_catch(&e, a, 3);
if(val) {
if(val != CODE_1) {
return val;
}
} else {
throw(&e, CODE_1);
}
try_catch_end(&e);
try_catch(&e, a, 3);
if(val) {
if(val != CODE_2) {
return val;
}
} else {
throw(&e, CODE_2);
}
try_catch_end(&e);
try_catch(&e, a, 3);
if(val) {
if(val != CODE_3) {
return val;
}
} else {
throw(&e, CODE_3);
}
try_catch_end(&e);
return 0;
}
int test3() {
int a[] = {CODE_1, CODE_2, CODE_3};
int val = try_catch(&e, &a[0], 1);
if(val) {
return CODE_1;
} else {
val = try_catch(&e, &a[1], 1);
if(val) {
return 0; // correct catch
} else {
val = try_catch(&e, &a[2], 1);
if(val) {
return CODE_3;
} else {
throw(&e, CODE_2);
}
try_catch_end(&e);
}
try_catch_end(&e);
}
try_catch_end(&e);
return 0;
}
int main() {
exception_init(&e);
test1();
int val = test2();
if (val) {
printf("error code test2: %d\n", val);
}
val = test3();
if (val) {
printf("error code test3: %d\n", val);
}
return 0;
}