J2EEOnline J2EE 






Java Exceptions  «Prev  Next»
Catching Exceptions in Java - Quiz
 
Each question is worth one point. Select the best answer for each question.

1. Examine the following snippet of code. What do you expect the output to be?
try {
   Integer number = new Integer("1");
   System.out.println("created a new Integer instance");
} 
catch (Exception e) {
   System.out.println("trouble in River City");
}
Please select the best answer.
  A. "created a new Integer instance"
  B. "trouble in River City"
  C. None of the Above


2. Which pair of keywords must you use when invoking a method that might throw an exception?
Please select the best answer.
  A. throw, catch
  B. try, catch
  C. catch, finally

3. Select the answer that best describes the purpose of the following catch block:
try {
  // Write to file
  // Read from file
} 
catch (java.lang.IOException e) {
  // Do something if . . .
}
  A. Closes the file that has been written to and read.
  B. Catches an exception if the file is not available for reading or writing.
  C. Catches an exception if the System.getProperty call fails.
Score =
Correct answers: