| 12 | } jmp_state; |
| 13 | |
| 14 | void setjmp_func(jmp_state* s, int level) { |
| 15 | int prev_jmp = s->jmp; |
| 16 | int c_jmp; |
| 17 | |
| 18 | if (level == 2) { |
| 19 | printf("level is 2, perform longjmp!\n"); |
| 20 | throw 1; |
| 21 | } |
| 22 | |
| 23 | c_jmp = current_exception_id++; |
| 24 | try { |
| 25 | printf("setjmp normal execution path, level: %d, prev_jmp: %d\n", level, |
| 26 | prev_jmp); |
| 27 | s->jmp = c_jmp; |
| 28 | setjmp_func(s, level + 1); |
| 29 | } |
| 30 | catch (int caught_eid) { |
| 31 | printf("caught %d\n", caught_eid); |
| 32 | if (caught_eid == c_jmp) { |
| 33 | printf("setjmp exception execution path, level: %d, prev_jmp: %d\n", |
| 34 | level, prev_jmp); |
| 35 | if (prev_jmp != -1) { |
| 36 | printf("prev_jmp is not empty, continue with longjmp!\n"); |
| 37 | s->jmp = prev_jmp; |
| 38 | throw s->jmp; |
| 39 | } |
| 40 | } else { |
| 41 | throw; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | printf("Exiting setjmp function, level: %d, prev_jmp: %d\n", level, prev_jmp); |
| 46 | } |
| 47 | |
| 48 | int main(int argc, char* argv[]) { |
| 49 | jmp_state s; |