An ON EXCEPTION statement is valid for the statement block that follows the ON EXCEPTION statement, all the statement blocks nested within the following statement block, and all the statement blocks that follow the ON EXCEPTION statement. It is not valid in the statement block that contains the ON EXCEPTION statement.
The pseudocode in Figure 468 shows where the exception is valid within the routine. That is, if error 201 occurs in any of the indicated blocks, the action labeled a201 occurs.
CREATE PROCEDURE scope() DEFINE i INT; . . . BEGIN -- begin statement block A . . . ON EXCEPTION IN (201) -- do action a201 END EXCEPTION BEGIN -- statement block aa -- do action, a201 valid here END BEGIN -- statement block bb -- do action, a201 valid here END WHILE i < 10 -- do something, a201 is valid here END WHILE END BEGIN -- begin statement block B -- do something -- a201 is NOT valid here END END PROCEDURE;