Lecture 16 Exception Handling
Lecture 16 Exception Handling
}
//Catch of Main(parent) try block
catch(Exception e3) {
//Exception Message
Aita Agrawal (CS F213) } 4/17/2023 7:41 AM 3
▪ Java finally block is a block that is used to execute important code such as
closing connection, stream etc.
▪ finally creates a block of code that will be executed after a try /catch
block has completed and before the code following the try/catch block
▪ The finally block will execute whether or not an exception is thrown
▪ If an exception is thrown, the finally block will execute even if no catch
statement matches the exception
▪ Useful for closing file handles and freeing up any other reserved resources
▪ The finally clause is optional
▪ However, each try statement requires at least one catch or a finally block