Chapter 11 30 questions 10 fill in the blank 10 true/false 10 multiple choice Fill in the Blank Questions 1. An exception __________ is code that executes when an exception is thrown. [handler] 2. Statements in a __________ block are always executed regardless of whether an exception is thrown or not. [finally] 3. The current method that is executing is always represented by the __________ block on the method call stack. [top] 4. The compiler analyzes __________ exceptions to determine if the containing method handles or declares the exception. [checked] 5. A __________ dialog box does not allow the user to access another window until it is closed. [modal] 6. The code that may generate an exception is contained in a __________ block. [try] 7. The code that is executed when an exception occurs is contained in a __________ block. [catch] 8. If a method encounters an error or an exceptional condition, it will __________ an exception. [throw] 9. Division by zero causes a(n) __________ to be thrown. [ArithmeticException] 10. Unchecked exceptions belong to subclasses of __________. [RuntimeExceoption] True/False Questions 1. When an exception is thrown, control is transferred to the appropriate catch block and does not resume in the try block. TRUE FALSE [TRUE] 2. A finally block is always required when using try and catch blocks. TRUE FALSE [FALSE] 3. Only one catch block can be associated with a given try block. TRUE FALSE [FALSE] 4. Dynamic scoping occurs when the call stack is used to search backwards through method calls to find a catch block. TRUE FALSE [TRUE] 5. A program terminates when an exception is thrown and there is not a corresponding catch block. TRUE FALSE [TRUE] 6. A finally block is executed only if the catch block is executed. TRUE FALSE [FALSE] 7. An exception is thrown when an error or abnormal condition is encountered. TRUE FALSE [TRUE] 8. The try block includes statements that are executed when an exception occurs. TRUE FALSE [FALSE] 9. The JOptionPane class contains methods for creating and displaying basic dialog boxes. TRUE FALSE [TRUE] 10. The integer division operator will throw a NumberFormatException when the denominator is zero. TRUE FALSE [FALSE] Multiple-Choice Questions 1. What method prints a list of all the methods that were called leading up to the method that threw the exception? A. RunTimeException() B. printStackTrace() C. catch() D. Exception() [B] 2. Which of the following is a checked exception? A. NullPointerException B. IndexOutOfBoundsException C. NumberFormatException D. IOException [D] 3. [B] What is the default icon displayed for a JOptionPane? A. PLAIN_MESSAGE B. INFORMATIONAL_MESSAGE C. WARNING_MESSAGE D. ERROR_MESSAGE 4. What is printed from the following code segment? int x = 5; try { if (x > 10) throw new Exception(x + “ is too large”); System.out.println(“Exiting try block”); } catch (Exception e) { System.out.println(“Error: “ + e.getMessage()); } A. B. C. D. 5 is too large Exiting try block Error: 5 is too large 5 is too large Exiting try block [B] 5. What is printed from the following code segment? int x = 35; try { if (x > 10) throw new Exception(x + “ is too large”); System.out.println(“Exiting try block”); } catch (Exception e) { System.out.println(“Error: “ + e.getMessage()); } A. B. C. D. 35 is too large Exiting try block Error: 35 is too large 35 is too large Exiting try block [C] 6. What type of exception is thrown from the following code segment? String s = “illerom”; s.substring(10); A. B. C. D. NumberFormatException ArithmeticException NullPointerException StringIndexOutOfBoundsException [D] 7. What type of exception is thrown from the following code segment? Integer.parseInt(“546.23”); A. B. C. D. [A] NumberFormatException ArithmeticException NullPointerException StringIndexOutOfBoundsException 8. What type of block handles exception? A. try B. catch C. throw D. finally [B] 9. What type of block throws exceptions? A. try B. catch C. throw D. finally [A] 10. What type of exception is raised when division by zero is attempted? A. ArithmeticException B. NumberFormatException C. NullPointException D. IndexOutOfBoundsException [A]