- Exceptions, completion, and user-defined conditions raised in a compound statement by any statement other than handler action statements are handled within that compound statement if an appropriate handler exists.
In nested compound statements, conditions that find no suitable handler in an inner compound statement are propagated to the outer statement in search of a handler.
The different scenarios possible when no handler is available to handle a condition in an inner compound statement, are described in the following table:
Where Condition is Raised Handler for Condition Result In a non-nested compound statement Exists in that statement The condition is handled and the stored procedure execution either continues or terminates based on the type of handler. Does not exist and the condition is: - An exception or unhandled user-defined condition
- A completion condition
- The stored procedure terminates.
- The stored procedure execution continues.
One of the following: - In a nested compound statement
- By a statement other than a handler action statement
Exists within that statement The condition is handled. Does not exist within that statement, then the immediate outer statement is searched for a suitable handler. - If a handler exists within that statement, the condition is handled.
- If no handler exists, the next outer compound statement is searched for a suitable handler.
If no appropriate handler exists in the outermost compound statement and the condition is:
- An exception or unhandled user-defined condition, the stored procedure terminates.
- A completion condition, the stored procedure execution continues with the statement following the statement that caused the condition.
- The rules for propagation and handling of exception, completion, and user-defined conditions raised by any handler action statement are different from the preceding rules.