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