Java Reference
In-Depth Information
14.13
Suppose that
statement2
causes an exception in the following
try-catch
block:
try
{
statement1;
statement2;
statement3;
}
catch
(Exception1 ex1) {
}
catch
(Exception2 ex2) {
}
statement4;
Answer the following questions:
Will
statement3
be executed?
■
If the exception is not caught, will
statement4
be executed?
■
■
If the exception is caught in the
catch
block, will
statement4
be executed?
14.14
What is displayed when the following program is run?
public class
Test {
public static void
main(String[] args) {
try
{
int
[] list =
new int
[
10
];
System.out.println(
"list[10] is "
+ list[
10
]);
}
catch
(ArithmeticException ex) {
System.out.println(
"ArithmeticException"
);
}
catch
(RuntimeException ex) {
System.out.println(
"RuntimeException"
);
}
catch
(Exception ex) {
System.out.println(
"Exception"
);
}
}
}
14.15
What is displayed when the following program is run?
public class
Test {
public static void
main(String[] args) {
try
{
method();
System.out.println(
"After the method call"
);
}
catch
(ArithmeticException ex) {
System.out.println(
"ArithmeticException"
);
}
catch
(RuntimeException ex) {
System.out.println(
"RuntimeException"
);
}
catch
(Exception e) {
System.out.println(
"Exception"
);
}
}
static void
method()
throws
Exception {