|
try
{
statement
statement
...
}
catch (ExceptionClass exceptionObject)
{
statement
statement
...
}
catch (ExceptionClass exceptionObject)
{
statement
statement
...
}
...
|
Example:
|
try
{
System.out.println("What is your name?");
String name = console.readLine();
System.out.println("Hello,"+name +"!");
}
catch (IOException exception)
{
exception.printStackTrace();
System.exit(1);
}
|
Purpose:
To execute one or more statements that may generate exceptions.
If an exception of a particular type occurs, then stop executing
those statements and instead go to the matching catch clause. If no
exception occurs, then skip the catch clauses.
|