1 If a class uses any method that has been defined to create exception objects, then the compiler must be notified of the intentions regarding this object. How is this notification commonly referred to in Java? and in actions that occur during the processing of an applet. Throwing and Handling Handle and Declare Code and Handle Throwing and Catching Java errors code or data errors standard errors user-defined errors 2 The finally clause is not executed under which one of the following conditions? 7 What is true of a catch block that reports a message for a specific type of exception? The code in the try block includes a break. The code in the try block includes a return. The System.exit() method is called within a try or catch block. The code in the try block executes properly. The catch block must specify the type of exception it is designed to catch. The catch block must have code to handle any type of exception and print the appropriate message. The catch block does not necessarily need to specify the type of exception. The system will know by the code that is included in the block. The catch block is followed by a finally block that prints the message specified by the catch block. 3 When you have statements in your code block that can throw exceptions, there are several choices for things you must do. Which one of the following is not one of these options? Do nothing. Ignore the exception Declare the exception Handle the exception Handle, re-throw and declare the exception 4 What is the purpose of a try block? The try block is used to catch unwanted types of objects. The try block contains code that may generate an exception. The try block throws exceptions in order to test the exception handling of the system. The try block is used to debug code that has not been proven and may contain exceptions. 5 Which class is the super class for all Exception and Error classes? Applet Graphics AWT Throwable 6 Certain errors are known and expected to occur during the processing of a method, specifically errors in accessing files, in obtaining network connections, in receiving data from a database, in sending instructions to a database, Which one of the following is used to categorize the errors listed above? 8 What are the steps that describe how to create your own customized exceptions? Create a class with the correct exception, in a method from the exception class throw the exception, and use the method in the try-catch block. Create a class that extends Exception, in a method from the exception class throw the exception, and use the method in a try-catch block. Create a class that extends Exception, in a method of another class throw the exception, and use the method that throws the exception in a trycatch block. Create a class that extends Exception, in a method from the exception class throw the exception, and use the method in a finally block. 9 In the code listing provided, why must "throws IOException" be included in the line "public static void main (String args [ ]) throws IOException"? "import java.io.*;" is used in the program. "throws IOException" is used in all main methods. The call stack unwinds and the exception must be handled by the main method. "aStudent.setName();" can throw an IOException. 10 What is the correct definition of a handler? A section of code in which an exception may occur. A section of code that executes when a button is clicked. A section of code that contains the instructions concerning what to do with an exception. The main section of code for the class that executes. 11 What must be done when a method re-throws an exception? You must declare the exception in the method signature. You must first catch the exception with a catch statement. You must use a subclass of the exception. You must unwind the call stack. 12 If present, which block of code will be executed when a try block completes without any exceptions? main catch finally return 13 What must be true when a method throws more than one type of exception? The method signature must list the exception types and order they are thrown. The method signature must list the exception types. The method signature must list the exception types and number of each exception type anticipated. The method signature must use the keyword multiple in the signature. 14 What is an exception? a representation of an exception condition unexpected code written by the programmer unexpected results after the program has terminated normally untrusted code such as a virus 15 Which of the following statements is correct? A try catch block has one or more try blocks and one or more catch blocks. A try catch block has one try block and one or more catch blocks. A try catch block has one try block and one catch block. A try catch block has one or more try blocks and one catch block. 16 Which one of the following statements correctly defines an exception? An exception is a representation of an error condition or any situation that is not the expected result of a method. An exception is a representation of a condition or situation that occurs when your code executes normally. An exception is the block of code that executes when your program terminates abnormally. An exception is an error that occurs at compile time. 17 Choose the item that best describes one of the results a program should have when the environment returns an unexpected result. Notify or alert the user there has been an error. Clear the screen and restart the machine. Contact Cisco Systems with the error code. Copy the original data to the error database. 18 What package contains the IOException class? java.util.* java.text.* java.io.* java.error.* 19 What happens when an uncaught exception occurs in the main() method? The program initiates. The program ends. The program prints. The program recompiles. 20 The order of the try, catch, and finally blocks is very important. Which of the following is not correct? The order of the try, catch, finally blocks must be in that order only. A finally block is not necessary, only a nice to have feature. Other blocks of code can exist between your try, catch, and finally blocks as long as the try block is first, some other code is second, catch blocks are next, followed by the finally block. A try block cannot exist without at least one catch block, or if no catch block exists then a finally block is required. The local variables should be declared in both the try block and the catch block. 23 What should be done when you have statements that can throw exceptions in your code? You should let the operating system handle all exceptions. You should include code from the handler class to catch the exception. You should declare the exception in a throws clause, or place the statements in a try/catch/finally block. You should ignore all exceptions. 21 What must be done when throwing an integer as an exception? 24 When an exception occurs in a try block, what happens to the code execution in the try block? Integers cannot be thrown. Declare integers as throwable. Import the exception class. Encapsulate the integer handler. The finally block is executed next. The exception is thrown. The catch blocks are executed. The try block is terminated. 22 How are local variables declared when using try and catch blocks, if you want to print their values when an exception occurs? 25 What does the programmer have to do to handle a user-defined exception? The local variables should be declared in the try block. The local variables should be declared in the catch block. The local variables should be declared locally outside the try and catch blocks. Write the exception as a start method. Handle the exception as an error. Write the exception as a part of the Component class. Handle it no differently than any other checked exception.