"Subclasses of the class Exception which aren't subclasses of RuntimeException require
mandatory exception handling." What are the practical implications of this statement? -
ANS-a. If a method can throw such an exception, then it should claim this truth via adding a
throws clause to the method heading.
B. If a routine includes any code that can generate such an exception, then the routine
should address the exception.
D. The ordinary can manage the exception with the aid of inclusive of the code in a try
statement that has a seize clause to handle the exception.
A switch assertion, most customarily has the form:
switch (expression)
case consistent-1:
statements-1
spoil;
...
The value of the expression can be:
i. Int
ii. Quick
iii. Byte
iv. Primitive char
v. Enum
vi. String
vii. Real variety - ANS-c. All, except vi and vii
Consider the following code (count on that comments are changed with actual code that
works as detailed):
public class TestExceptions
static void e()
// Might cause any of the subsequent unchecked exceptions to be
// thrown:
// Ex1, Ex2, Ex3, Ex4
static void April()
strive
e();
catch (Ex1 ex)
, System.Out.Println("April caught Ex1");
static void March()
attempt
April();
capture (Ex2 ex)
System.Out.Println("March caught Ex2");
// now cause exception Ex1 to be thrown
static void February()
try
March();
catch (Ex1 ex)
System.Out.Println("February stuck Ex1");
capture (Ex3 ex)
System.Out.Println("February caught Ex3");
static void a()
strive
February();
trap (Ex4 ex)
System.Out.Println("January stuck Ex4");
// now motive exception Ex1 to be thrown
seize (Ex1 ex)
System.Out.Println("January caught Ex1");
public static void major - ANS-a.
The application prints:
April caught Ex1
The application prints:
March caught Ex2
February caught Ex1
The software prints:
February caught Ex3
The application prints:
January stuck Ex4
And execution stops due to an uncaught exception Ex1 thrown in foremost()
Consider the subsequent code: