The catch keyword is used to define exception handling blocks in try-catch or try-catch-finally statements.
try
{
<block that may throw exceptions>
}
catch (<java.lang.Exception or subclass> e)
{
<code to handle exception e>
}
try { <block that may throw different exceptions> } catch (FooException e) { <code to handle FooException e> } catch (BarException e) { <code to handle BarException e> }
try
{
<block that may throw exceptions>
}
catch (<java.lang.Exception or subclass> e)
{
<code to handle exception e>
}
finally
{
<statements that execute with or without exception>
}
The opening and closing curly braces { and } are part of the syntax of the catch clause and may not be omitted even if the clause contains a single statement.
Every try block must have at least one catch or finally clause.
If a particular exception class is not handled by any catch clause, the exception propagates up the call stack to the next enclosing try block, recursively. If an exception is not caught by any enclosing try block, the Java interpretor will exit with an error message and stack trace.