- try-block
In general, statements that may cause exception will be placed in try-block - catch-block
You can catch some of exception that may be threw in try-block. If an exception is catched, the work flow is "try -> catch -> finally (if exists) -> statements after try-catch-finally -> return; othewise, the work flow is "try -> finally (if exits) -> return immediately; - finally-block
You need to do some clean up task here. No matter if any exception is threw in try-block or not, no matter if the exception is catched in catch-block, statements in finally-block will be executed. i.e:
SomeType a = null;
try
{
a = new SomeType();
a.xxx();
...
}
catch (XXX e)
{
}
finally
{
if (a != null) {destroy a;}
} - Statements after try-catch-block:
if an exception is threw and it is not catched, the statements after try-catch-finally block won't be executed, the method will be return immediatelly once the finally-clock is executed if it exists. - If an exception is not catched, you must declare this behind method declaration statement, such as xxx 'public void myMethod(xxx) throws AException, BException, ...'