Try Catch
Introduction
In a function, if an exception is occur , the exception object containing type and message will be created which is called throw an exception
The list of method is called when the exception is thrown is called Call Stack
The block of the functions is called Exception Handler
If the exception handler is not found when exception occur, the default handler will print the information and terminate the program
We can add try catch in order to prevent from the termination of the program
Throw
Try-With-Resource
The
try
-with-resources statement is atry
statement that declares one or more resources. A resource is an object that must be closed after the program is finished with it. Thetry
-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implementsjava.lang.AutoCloseable
, which includes all objects which implementjava.io.Closeable
, can be used as a resource.Before using try-with-resource
After using try-with-resource
Last updated
Was this helpful?