This block wraps code that might throw an exception.
This block catches the named exception that was thrown.You may have as many catch blocks for a try as you like.
Some exceptions are required to be caught, others are not.
This block of code will always execute, whether an exception is thrown or not. When an exception is thrown, the JVM first looks for a catch for that exception. If it is found, it will execute that code.exception thrown
catch found?
yes:
execute code
finally clause?
yes: execute code
no: exit method
no: exit method
exception not thrown
finally clause?
yes: execute code
code outside of try-catch?
yes: execute code
Put your clean-Up code goes here. Set objects to null, mainly.
There are times you do not want to catch exceptions. Instead, you pass them up the chain.