This statement enhances error handling within the broker by incorporating an exception handler.
You can declare handlers in both explicitly declared (BEGIN...END) scopes and implicitly declared scopes, for example, the ELSE clause of an IF statement. The handler declaration list must be the first item within any scope.
In the absence of exceptions, the presence of handlers has no effect on the behavior or performance of an SQL program. If an exception occurs, the SQL state of the exception is compared with the SQL states associated with any relevant handlers, until either the exception leaves the node (just as it would if there were no handlers) or a matching handler is found. Within any one scope, handlers are searched in the order they are declared, that is, first to last. Scopes are searched from the innermost to outermost.
The SQL state values provided in DECLARE... HANDLER... statements can be compared directly with the SQL state of the exception (LIKE not specified) or can be compared using wild card characters (LIKE specified).
In the latter case, underscore and percent characters represent single and multiple character wild cards respectively and, the state values are matched according to the rules of the LIKE operator. This allows all exceptions of a general type to be handled without having to exhaustively list them.
If a matching handler is found, the SQLSTATE and other special registers are updated (according to rules described below) and the handler's statement is processed.
As this is in principle a single statement, it is likely to be a compound statement (BEGIN...END) containing many statements. There is no special behavior associated with these statements and there are no special restrictions. They can, for example, contain RETURN, ITERATE, or LEAVE statements and these affect their containing routines and looping constructs in the same way as if these statements were contained in the scope itself. Handlers can contain handlers for exceptions occurring within the handler itself
Handlers can absorb exceptions so preventing their reaching an input node and, therefore, causing the transaction to be committed rather than rolled back.
Notices |
Trademarks |
Downloads |
Library |
Support |
Feedback
![]() ![]() |
ak20700_ |