Please enable JavaScript.
Coggle requires JavaScript to display documents.
Using try Statement (Adding a finally block (Structure (try{}catch(Excepti…
Using try Statement
Adding a finally block
Always executes
Not require a catch block
Structure
try{}catch(Exception e){}finally{}
Always be after catch
Needs appear with try
Used to close files and databases
Catching Various Types of Exceptions
Recognize checked and unchecked exceptions
Determine exceptions are subclasses
Only executes superclass exception
If comes first
An compile error
Subclass comes after
Unreachable catch block
e.g. try{}catch(RuntimeException e){}catch(Exception e){}
try
Handle an exception
Separate logic
try{ }catch(Exception e){}
try - keyword
{} body of try, the code here
catch - keyword
Execute when throw Exception
Throwing a Second Exception
Catch
Can have other try statement
Finally
Can have other try statement