#include <iostream.h>
struct my_exception { };
struct your_exception { };
void put_line (char *s, int i) {
cout << s << i << endl;
}
void p(int i) {
put_line ("Entering P:", i);
switch (i)
{
case 1:
put_line ("Case 1 in P:" ,i);
throw my_exception();
case 2:
put_line ("Case 2 in P:", i);
throw your_exception();
}
put_line("Leaving P:", i);
}
void q(int i) {
put_line ("Entering Q:", i);
try {
switch (i) {
case 1:
put_line ("Case 1 in Q:", i);
p(i+1);
break;
case 2:
put_line ("Case 2 in Q:", i);
p(i-1);
break;
case 3:
put_line ("Case 3 in Q:", i);
p(i-2);
break;
}
put_line("Leaving Q:", i);
}
catch (my_exception &e) {
put_line("my_exception in Case 2 of Q:", i);
}
catch (your_exception & e) {
put_line("your_exception in P:", i);
}
}
void main() {
int i;
try {
for (i=1; i<=3; i++)
q(i);
put_line("Leaving main:", i);
}
catch (my_exception &e) {
put_line ("my_exception in Main:", i);
}
}