13.6.7 Condition Handling

Conditions may arise during stored program execution that require
special handling, such as exiting the current program block or
continuing execution. Handlers can be defined for general
conditions such as warnings or exceptions, or for specific
conditions such as a particular error code. Specific conditions
can be assigned names and referred to that way in handlers.

Another statement related to conditions is GET
DIAGNOSTICS. The GET DIAGNOSTICS
statement is not supported until MySQL 5.6.

Before MySQL 5.6.3, if a statement that generates a warning or
error causes a condition handler to be invoked, the handler may
not clear the diagnostic area. This might lead to the appearance
that the handler was not invoked. The following discussion
demonstrates the issue and provides a workaround.

Suppose that a table t1 is empty. The following
procedure selects from it, raising a No Data condition:

CREATE PROCEDURE p1()
BEGIN
DECLARE a INT;
DECLARE CONTINUE HANDLER FOR NOT FOUND
BEGIN
SET @handler_invoked = 1;
END;
SELECT c1 INTO a FROM t1;
END;

As can be seen from the following sequence of statements, the
condition is not cleared by handler invocation (otherwise, the
SHOW WARNINGS output would be
empty). But as can be seen by the value of
@handler_invoked, the handler was indeed
invoked (otherwise its value would be 0).