| 1 | #include <exception> |
|---|---|
| 2 | #include <stdio.h> |
| 3 | |
| 4 | int throws_exception_on_even (int value); |
| 5 | int intervening_function (int value); |
| 6 | int catches_exception (int value); |
| 7 | |
| 8 | int |
| 9 | catches_exception (int value) |
| 10 | { |
| 11 | try |
| 12 | { |
| 13 | return intervening_function(value); // This is the line you should stop at for catch |
| 14 | } |
| 15 | catch (int value) |
| 16 | { |
| 17 | return value; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | int |
| 22 | intervening_function (int value) |
| 23 | { |
| 24 | return throws_exception_on_even (value: 2 * value); |
| 25 | } |
| 26 | |
| 27 | int |
| 28 | throws_exception_on_even (int value) |
| 29 | { |
| 30 | printf (format: "Mod two works: %d.\n", value%2); |
| 31 | if (value % 2 == 0) |
| 32 | throw 30; |
| 33 | else |
| 34 | return value; |
| 35 | } |
| 36 | |
| 37 | int |
| 38 | main () |
| 39 | { |
| 40 | catches_exception (value: 10); // Stop here |
| 41 | return 5; |
| 42 | } |
| 43 |
