Hi Guys,
The following is from
here 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 answers are given as 2 and 4, 4 is ok, but how come 2 and why not 5?? And will this ever compile??
Confusing.