2 Answers
The following about try and catch blocks:
- If no exception is thrown in a try block, the catch block that is associated with the try block is ignored and control is transformed to the statements following the last catch block.
- If an exception occurs in a try block, the remaining statements in that block are ignored.
- The appropriate catch block is searched from the first catch and an appropriate catch block is selected.
- Once a catch block is executed, remaining catch blocks are ignored and control is transferred to the point immediately after the last catch block.
- The catch block that has three dots is designed to catch any type of exception.
The following about try and catch blocks:
- If no exception is thrown in a try block, the catch block that is associated with the try block is ignored and control is transformed to the statements following the last catch block.
- If an exception occurs in a try block, the remaining statements in that block are ignored.
- The appropriate catch block is searched from the first catch and an appropriate catch block is selected.
- Once a catch block is executed, remaining catch blocks are ignored and control is transferred to the point immediately after the last catch block.
- The catch block that has three dots is designed to catch any type of exception.
consider the following catch block:
catch(int a)
{
//code to handle the exceptions
}
Observe the following block:
- The parameter is called a catch block parameter.
- The int type of the parameter indicates that it can catch an exception of type int.
- A catch block can have zero parameters or one parameter. It should not have more than one parameter.
- The value thrown by the try block will be equal to the parameter in the catch block.