void foo () { try { throw new Exception1 (); print (" A "); throw new Exception2 (); print (" B "); } catch ( Exception1 e1 ) { print " handler1 "; } print (" C "); throw new Exception2 (); } void main () { try { try { foo (); print (" D "); } catch ( Exception1 e1 ) { print " handler2 "; } print (" E "); } catch ( Exception2 e2 ) { print " handler3 "; } } Write down the output of the program and justify why it is the output. Instead of the “replacement” semantics of exception handling used in modern languages, a very early design of exception handling introduced in the PL/I language uses a “binding” semantics. In particular, the design dynamically tracks a sequence of “catch” blocks that are currently active; a catch block is active whenever the corresponding try block is active. What will be the output of the following program if the language uses the “binding” semantics? Give the reasoning for your answer.
void foo () {
try {
throw new Exception1 ();
print (" A ");
throw new Exception2 ();
print (" B ");
}
catch ( Exception1 e1 ) {
print " handler1 ";
}
print (" C ");
throw new Exception2 ();
}
void main () {
try {
try {
foo ();
print (" D ");
}
catch ( Exception1 e1 ) { print " handler2 "; }
print (" E ");
}
catch ( Exception2 e2 ) { print " handler3 "; }
}
Write down the output of the
sequence of “catch” blocks that are currently active; a catch block is active whenever the corresponding try block is active. What will be the output of the following program if the language uses the “binding” semantics? Give the reasoning for your answer.
Step by step
Solved in 4 steps with 2 images