Java OCA OCP Practice Question 2834

Question

Which of the following cannot fill in the blank? (Choose all that apply.)

public void read() throws SQLException { 
   try { 
     readFromDatabase(); 
   } catch (_________________ e) { 
     throw e; 
   } 
} 

private void readFromDatabase() throws SQLException { } 
  • A. Exception
  • B. RuntimeException
  • C. SQLException
  • D. SQLException | IOException
  • E. SQLException | RuntimeException


D.

Note

Choice A is allowed because Java 7 and later "translates" Exception in a catch block to the correct one.

Choices C and E are allowed because they actually catch a SQLException.

Choice D is not allowed because there is no IOException declared.

Choice B is allowed because a method does not have to handle an exception if it declares it.




PreviousNext

Related