posted 17 years ago
javabeat Question
Consider the following code snippet:
void m1() throws Exception{
try {
// line1
}
catch (IOException e) {
throw new SQLException();
} catch(SQLException e)
{ throw new InstantiationException();
} finally {
throw new CloneNotSupportedException() // this is not a RuntimeException.
}}
Which of the following statements are true? Select 2 correct options
(1) If IOException gets thrown at line1, then the whole method will end up throwing SQLException
(2) If IOException gets thrown at line1, then the whole method will end up throwing CloneNotSupportedException
(3) If IOException gets thrown at line1, then the whole method will end up throwing InstantiationException()
(4) If no exception is thrown at line1, then the whole method will end up throwing CloneNotSupportedException
(5) If SQLException gets thrown at line1, then the whole method will end up throwing InstantiationException()
The given answers are 2 and 4.
But when i run the program with line1 throwing IOException,i got the compile error at catch (SQLException e) . telling SQLException is never thrwon in try.
and also if i run the program with line1 thrown no exception,i got the compile error at catch (SQLException e) and catch (IOException e) .