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

Info icon This 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
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern