You are on page 1of 1

5) What happens if a try catch finally statement does not

have a catch clause to handle an exception that is thrown


within the body of the try statement?

Ans: - If the exception is not handled by any provided catch block, the JVM
default exception handler handle it.  In this case, finally block will be
executed followed by default exception handling mechanism.

Input (ECE/17/
try
{
     System.out.println ("try block");
     throw new NullPointerException ("Null occurred");
}
finally
{
     System.out.println ("finally block");
}

Output
try block
finally block

Exception in thread "main" java.lang.NullPointerException: Null occurred


at Exception.main (Exception.java:8)

Roll No-. (ECE/17/15),(ECE/17/16),(ECE/17/23)

You might also like