Exceptions Test Bank Docx Chapter.10 - Java Foundations 4th Edition | Test Bank with Answer Key by John Lewis by John Lewis, Peter DePasquale, Joe Chase. DOCX document preview.
Chapter 10: Exceptions
Multiple Choice Questions:
1) A(n) _____________________ is an object that defines an unusual or erroneous situation that is typically recoverable.
a) error
b) exception
c) interface
d) try block
e) catch block
2) A(n) _____________________ is an object that defines an erroneous situation from which the program usually cannot recover.
a) error
b) exception
c) interface
d) try block
e) catch block
3) A(n) ____________________ can be used to find the exact line where an exception was thrown during program execution.
a) interface
b) call-stack trace
c) try block
d) catch block
e) none of the above
4) A(n) ____________________ is used to identify a block of statements that may cause an exception.
a) call-stack trace
b) error
c) catch block
d) try block
e) none of the above
5) A(n) ____________________ is used to specify how certain exceptions should be handled.
a) finally block
b) try block
c) catch block
d) error
e) none of the above
6) Every line of a(n) __________________ is executed no matter what exceptions are thrown.
a) try block
b) call stack trace
c) catch block
d) interface
e) finally block
7) If an exception is not caught, a program will __________________________ .
a) not compile
b) terminate abnormally
c) print a message and continue executing
d) all of the above
e) neither a, b nor c
8) The Exception class and the Error class are subclasses of the ___________________ class.
a) Throwable
b) Catchable
c) RuntimeProblem
d) CompilerProblem
e) none of the above
9) ____________ is the process of catching an exception in the chain of method calls from the method where the exception occurred up to the main method.
a) Error handling
b) Exception handling
c) Exception propagation
d) Catch block nesting
e) Finally block nesting
10) A(n) ________________ is an ordered sequence of bytes.
a) exception
b) error
c) input-output flow
d) stream
e) none of the above
11) Which of the following represents the standard input stream?
a) System.in
b) System.out
c) System.err
d) System.instream
e) System.outstream
12) Which of the following file streams should be explicitly closed to ensure that written data is properly retained?
a) output
b) input
c) error
d) writable
e) readable
13) Which of the following exception types must always be caught unless they are contained in methods that throw them in the method header?
a) file stream
b) IO
c) checked
d) unchecked
e) none of the above
14) Which of the following exceptions are unchecked?
a) RuntimeException
b) IllegalAccessException
c) NoSuchMethodException
d) ClassNotFoundException
e) none of the above
15) Which of the following methods are part of the Exception class and can be used to give information about a thrown exception?
a) getInfo
b) printInfo
c) printStackTrace
d) getStackTrace
e) none of the above
1) Files that are open for output from a program must be explicitly closed in the program.
2) Unchecked exceptions must be caught or propogated, or a program will not compile.
3) A finally clause is always required in a try-catch block.
4) Attempting to divide by zero will result in an Error being thrown, not an Exception.
5) Every line in a catch block is guaranteed to be executed in all situations.
6) An exception will be propagated until it is caught and handled or until it is passed out of the main method.
7) A throw statement is used to begin exception propagation.
8) The getMessage method of the Exception class prints out the stack trace, which helps the user to track down the source of the exception.
9) When accessing an element of an array, if the index is outside of the range of the indexes of the array, an exception is thrown.
10) In practice, it is important to catch all exceptions that might be thrown by a program.
1) What is a try block?
2) What is a catch clause?
3) How is a finally clause different from a try block and a catch clause?
4) What is the difference between a checked exception and an unchecked exception?
5) How are input and output streams similar? How are they different?
6) Consider the following code fragment.
int [] a = new int[50];
a[50] = 100;
Will this code fragment throw an exception? Explain.
7) Write a short snippet of code that converts the first element of the String[] args array to an integer. It should catch an exception and print out a message if the first element cannot be converted to an integer.
8) Give two examples of methods in the Exception class that can be used to output information about the Exception.
9) Is an exception an object? Explain.
10) What is exception prorogation, and how does it work in Java?
11) Is the Exception class a subclass of the Error class? Explain.
12) How must IOExceptions be addressed in a program?
13) What are the standard I/O streams?
14) How does a method throw an exception?
15) Write a code fragment that will throw an ArithmeticException. Your code fragment should not use the throw statement.
Document Information
Connected Book
Java Foundations 4th Edition | Test Bank with Answer Key by John Lewis
By John Lewis, Peter DePasquale, Joe Chase