Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 Exceptions class El extends Exception {}; class E2 extends El class E3 extends

ID: 3903553 • Letter: 1

Question

1 Exceptions class El extends Exception {}; class E2 extends El class E3 extends El class E4 extends E3 ; class E5 extends E3 ; class F1 extends Exception ; class F2 extends F1 class F3 extends F1 class F4 extends F1 In the following, we will use modifications to variables to summarise actions. This code that follows is intended to illustrate concepts and is deliberately not a model of clarity. 2 Exercise Assume x, y are member variables. ConsiderWork out the values of x, y if fO were to the following code x-0, y-0; try throw the following types of exception: 1. F2 2. F3 3. F4 . E4 try catch (F3 e) { x+ 1 catch (F1 e) { x+ 10; catch (F4 e) x + 100: catch (E5 e) y+-20; catch (Exception e) y+-100

Explanation / Answer

a) When F1 exception is thrown then, it will be caught by outer catch by generic exception handler.

Value of x = 0

Value of y = 100

b) Exception will be caught by second catch block

Value of x = 1

Value of y = 20

c) Exception will be caught by third catch block

Value of x = 100

Value of y = 20

d) Exception will be caught by outer catch block

Value of x = 0

Value of y = 100