Consider the following code snippet with exceptions. Note that the main function calls foo in the nested try block. void foo () { try { throw new Exception1(); print ("A"); } throw new Exception2(); print ("B"); catch (Exception e) { 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"; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

b) Instead of the “replacement” semantics of exception handling used in modern languages
(i.e., the semantics introduced in lecture), 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 corre-
sponding try block is active. Moreover, whenever an exception is thrown, the sequence of active
“catch” blocks will be traversed (in a first-in-last-out manner) to find a matching handler. Fur-
thermore, execution will resume at the statement following the one that throws exception, rather
than the next statement after the matching “catch” block as we have seen in the “replacement”
semantics. What will be the output of the following program if the language uses the “binding” semantics?
Briefly justify your answer

1
2
3
4
S
6
7
8
9
10
11
12
13
14
2222222222
15
16
17
18
19
20
21
22
23
Consider the following code snippet with exceptions. Note that the main function calls foo in the
nested try block.
void foo () {
try {
throw new Exception1();
print ("A");
throw new Exception2();
print ("B");
24 }
}
catch (Exception1 e1) {
print "handler1";
print ("C");
throw new Exception2 ();
void main () {
try
try {
2
foo ();
print ("D");
123 MPSCA
catch (Exception1 e1) print "handler2";
print ("E");
}
catch (Exception2 e2)
(
print "handler3"; }
AND
2023 CS
Transcribed Image Text:1 2 3 4 S 6 7 8 9 10 11 12 13 14 2222222222 15 16 17 18 19 20 21 22 23 Consider the following code snippet with exceptions. Note that the main function calls foo in the nested try block. void foo () { try { throw new Exception1(); print ("A"); throw new Exception2(); print ("B"); 24 } } catch (Exception1 e1) { print "handler1"; print ("C"); throw new Exception2 (); void main () { try try { 2 foo (); print ("D"); 123 MPSCA catch (Exception1 e1) print "handler2"; print ("E"); } catch (Exception2 e2) ( print "handler3"; } AND 2023 CS
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Custom Exception class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education