The TRY Statement
General Formats
Syntax Rules
- Identifier-1 must be an object reference of class System.Exception or a subclass of System.Exception.
General Rules
- Execution of the TRY statement begins with imperative-statement-1.
- If an exception is raised during the execution of imperative-statement-1, each CATCH phrase is examined in the order specified until one is found for which identifier-1 is either a descendant of or equal to the class of the exception that was thrown. If such an identifier-1 is found, the associated imperative-statement-2 is executed. Execution continues according to the rules for each statement specified in imperative-statement-2. If a control branching or conditional statement that causes explicit transfer of control is executed, control is transferred in accordance with the rules for that statement; otherwise, upon completion of the execution of imperative-statement-2, control is transferred to imperative-statement 3, if specified, or to the end of the TRY statement.
- If no exception is raised during the execution of imperative-statement-1, execution continues according to the rules for each statement specified in imperative-statement-1. If a control branching or conditional statement that causes explicit transfer of control is executed, control is transferred in accordance with the rules for that statement; otherwise, upon completion of the execution of imperative-statement-1, control is transferred to imperative-statement 3, if specified, or to the end of the TRY statement.
- Execution of imperative-statement-3 continues according to the rules for each statement specified in imperative-statement-3. If a control branching or conditional statement that causes explicit transfer of control is executed, control is transferred in accordance with the rules for that statement; otherwise, upon completion of the execution of imperative-statement-3, control is transferred to the end of the TRY statement