19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

14.13 Suppose that statement2 causes an exception in the following try-catch block:<br />

try {<br />

statement1;<br />

statement2;<br />

statement3;<br />

}<br />

catch (Exception1 ex1) {<br />

}<br />

catch (Exception2 ex2) {<br />

}<br />

statement4;<br />

Answer the following questions:<br />

■ Will statement3 be executed?<br />

■ If the exception is not caught, will statement4 be executed?<br />

■ If the exception is caught in the catch block, will statement4 be executed?<br />

14.14 What is displayed when the following program is run?<br />

public class Test {<br />

public static void main(String[] args) {<br />

try {<br />

int[] list = new int[10];<br />

System.out.println("list[10] is " + list[10]);<br />

}<br />

catch (ArithmeticException ex) {<br />

System.out.println("ArithmeticException");<br />

}<br />

catch (RuntimeException ex) {<br />

System.out.println("RuntimeException");<br />

}<br />

catch (Exception ex) {<br />

System.out.println("Exception");<br />

}<br />

}<br />

}<br />

14.15 What is displayed when the following program is run?<br />

public class Test {<br />

public static void main(String[] args) {<br />

try {<br />

method();<br />

System.out.println("After the method call");<br />

}<br />

catch (ArithmeticException ex) {<br />

System.out.println("ArithmeticException");<br />

}<br />

catch (RuntimeException ex) {<br />

System.out.println("RuntimeException");<br />

}<br />

catch (Exception e) {<br />

System.out.println("Exception");<br />

}<br />

}<br />

static void method() throws Exception {<br />

14.4 More on Exception Handling 533

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!