class Demo
{
public static void main(String args[]) throws java.io.IOException
{
try(FileInputStream fin = new FileInputStream("Demo.txt"))
{
//This block is executed successfully
}
System.out.println("Will it be executed if error occurs in try clause");
}
}
Suppose that the code in try block
is executed successfully as mentioned in the code, and some exception
occurs in try with resource clause
, that means exception occurs in auto closing
of file.
How that exception in the try with resource clause
will be handled?
What I want to ask is that will that exception be thrown to JVM and will terminate my program abruptly and the println
statement will not be executed?
Can I catch that exception so that remaining program can also be executed?
only add catch clause, to catch the exception otherwise program will be terminated