above code works fine.
but at line 1 ,run-time exception has never been thrown,so i guess it should be the error coz "i have read not to use the exception that has never been thrown in corresponding try block else compiler error".
please justify above statement.why it is not error?
Pedro Kowalski wrote:Howdy
The RuntimeExceptions are not checked if they are thrown from the try block, because they are... unchecked.
They can occur or don't so there is no way you can say they will ever be thrown from the try clause.
that means RuntimeExceptions if used unnecessarily in catch will not harm.
but checked exceptions are evil in this case.