Syntax of try{} / catch{}
Here is ONE form of the try/catch structure
(there are other forms soon to be discussed):
try
{
// statements, some of which might
// throw an exception
}
catch ( SomeExceptionType ex )
{
// statements to handle this
// type of exception
}
.... // more catch blocks
catch ( AnotherExceptionType ex )
{
// statements to handle this
// type of exception
}
// Statements following the structure
Here are a few syntax rules:
- The statements in the
try{} block can include:
- Statements that always work.
- Statements that might throw an exception of one type or another.
- There can be one or several
catch{} blocks.
- Also, there can be no
catch{} block.
This will be discussed in a few pages.
- Each
catch{} block describes the type of exception it handles.
|