Java Reference
In-Depth Information
// Some code that may cause a method to create an exception:
TextMessage myTextMessage = new TextMessage;
myTextMessage.getTranslation ();
// Some more code, which will execute if no exception has been created:
System.out.println ("No exception " +
myTextMessage.getmMsgText() );
}
// The exception handler logic.
// This will execute only if getTranslate() creates an exception of type
// NoDatabaseAvailableException.
System.out.println (e.getMessage() );
}
Statements inside the
try
code block will stop executing as soon as an exception
is created. If no exceptions are created, or if your class has caught and handled the ex-
ception, your class will continue with the statement after the
try...catch
code block.
Your class can handle multiple exceptions that may be created by statements in
the
try
code block simply by adding an additional
catch
code block after some
other
catch
code block.
try {
...
}
catch (NoDatabaseAvailableException e){
...
}
catch (IOException e){
// The exception handler logic for all other I/O conditions.