Exceptions Answers

Exceptions Answers - C f(10 X"bye"...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Answers to Self-Study Questions Test Yourself #1 Test Yourself #2 What is printed for each of the four runs? 1. d caught Ex1 2. c caught Ex2 b caught Ex1 3. b caught Ex3 4. a caught Ex4 execution stops due to uncaught exception Ex1 thrown in main Question 1: static void g() throws Ex1, Ex3 { try { f(); } catch (Ex1 ex1) { System.out.println("Ex1 caught"); } catch (Ex2 ex2) { System.out.println("Ex2 caught"); throw new Ex1(); } } Question 2: Part A. A. f(0, X, "hi"); nothing printed an uncaught ArithmeticException is thrown B. f(10, X, ""); prints "in finally clause" an uncaught StringIndexOutOfBoundsException is thrown
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: C. f(10, X, "bye"); prints "array error", "in finally clause" an uncaught InternalError is thrown D. f(10, X, null); prints "null ptr", "in finally clause", "after try block" Part B. Function f doesn't need to have a throws clause that lists the uncaught exceptions that it might throw because only uncaught CHECKED exceptions need to be listed in a method's throws clause. The uncaught exceptions that f might throw are all UNCHECKED exceptions. Page 1 of 1 Exceptions Answers 2008/3/27 http://pages.cs.wisc.edu/~cs367-1/topics/Exceptions/answers.html...
View Full Document

This note was uploaded on 03/27/2008 for the course CS 302 taught by Professor Willbenton during the Fall '07 term at University of Wisconsin.

Ask a homework question - tutors are online