CPSC150 EH30 1

CPSC150 EH30

Q1: Which of the following statements is not true?

a. Exception handling enables programmers to write robust and fault-tolerant programs.

b. Exception handling can only catch the exception but cannot resolve the exception.

c. Exception handling can resolve exceptions.

d. The Java 2 Platform, Standard Edition, Version 1.4 introduced the new chained exception feature.

Q2: Intermixing program and error-handling logic:

a. increase a program’s performance, because the program does not need to perform tests to determine whether the task executed correctly and the next task can be performed.

b. should be used in place of exception handling where possible.

c. can degrade a program’s performance, because the program must perform (potentially frequent) tests to determine whether the task executed correctly and the next task can be performed.

d. None of the above.

Q3: When an exception occurs it is said to have been:

a. caught.

b. thrown.

c. declared.

d. handled.

Q4: To catch an exception, code must be enclosed in a

a. throws block.

b. catch block.

c. try block.

d. finally block.

Q5: Exceptions can occur:

a. from the Java Virtual Machine.

b. through explicitly mentioned code in a try block.

c. through calls to other methods made in a try block.

d. All of the above.

Q6: In the catch block below, what is arithmeticException?

catch ( ArithmeticException arithmeticException )

{

System.err.printf( arithmeticException );

} // end catch

a. The type of the exception being caught.

b. The name of catch block’s exception parameter.

c. A finally block.

d. An exception handler.

Q7: An uncaught exception:

a. is a possible exception that never actually occurs during the execution of the program.

b. is an exception that occurs for which the matching catchclause is empty.

c. is an exception that occurs for which there are no matching catchclauses.

d. is another term for a thrown exception.

Q8: Which of the following statements about try blocks is true?

a. The try block must be followed by at least one catch block.

b. The try block must be followed by a finally block.

c. The try block should contain statements that may process an exception.

d. The try block should contain statements that may throw an exception.

Q9: What is the difference between a try block and a try statement?

a. There is no difference; the terms can be used interchangeably.

b. A try statement refers to the block of code following the keyword try, while the try block refers to the try keyword and the block of code following this keyword.

c. The try block refers to the keyword try followed by a block of code. The try block and its corresponding catch and/or finallyclauses together form a try statement.

d. The try statement refers to the keyword try followed by a block of code. The try statement and its corresponding catch and/or finallyclauses together form a try block.

Q10: All exception classes inherit, either directly or indirectly, from:

a. class Error.

b. class RuntimeException.

c. class Throwable.

d. None of the above.

Q11: Which of the following exceptions is a checked exception?

a. ArithmeticException.

b. IOException.

c. RuntimeException.

d. InputMismatchException.

Q12: If the catch-or-declare requirement for a checked exception is not satisfied:

a. the compiler will issue an error message indicating that the exception must be caught.

b. the compiler will issue an error message indicating that the exception must be caught or declared.

c. the stack trace will be displayed indicating the exception that has occurred and where it occurred.

d. the stack trace will be displayed, along with a message indicating that the exception must be caught.

Q13: Which of the following statements is true?

a. The code in a finally block is executed only if an exception occurs.

b. The code in a finally block is executed only if an exception does not occur.

c. The code in a finally block is executed only if there are no catch blocks.

d. None of the above are true.

Q14: After a finally block has finished executing:

a. control proceeds to the first statement after the finally block.

b. control returns to the throw point.

c. the application exits.

d. control proceeds to the first statement after the last catch block.

Q15: Which of the following statements is true?

a. The throw statement is used to throw an exception.

b. The throw statement is used to specify that a method will throw an exception.

c. The throw statement is used to access an exception parameter.

d. All of the above.

Q16:

Use inheritance to create an exception superclass (called ExceptionA) and exception subclass ExceptionB and ExceptionC, where ExceptionB inherits from ExceptionA and ExceptionC inherits from ExceptionB. Write a program to demonstrate that the catch block for type ExceptionA catches exceptions of types ExceptionB and ExceptionC.