Java   View all facts   Glossary   Help
syntactic unit > statement > control flow statement > exception statement
Next control flow statement: label statement    Up: control flow statement    Previous control flow statement: decision making statement   

exception statement comparison table
Subject have syntax have example be part of have purpose see also have part
throws statement 
throw new MyException("my exceptional condition occurred");
method bodyto generate an exceptionthrows clause 
try-catch-finally statement
try{
statements
} catch (exception_type1 identifier1) {
statements
} catch (exception_type2 identifier2) {
statements
...
} finally {
statements
}
//Any division by zero that occurs when executing the try block will result in execution of the catch block. 
//Once either block completes, execution continues at the statement after the catch block.
try
{
result = numerator / denominator;
validResult = true;
}
catch (ArithmeticException e)
{
validResult = false;
}
 to handle exceptions try block, catch block(s), finally block

Next control flow statement: label statement    Up: control flow statement    Previous control flow statement: decision making statement