How to determine if there was an exception in the handler in MySQL?

Viewed 28

I use handler in my function. How to find out if an exception occurred while executing the handler body?

DECLARE EXIT HANDLER FOR SQLEXCEPTION 
BEGIN
INSERT INTO ...
END;
1 Answers

You can create a HANDLER for your exception and you can set settings or variable values as you like:

DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
SET hasError = 1;

And later you can check the value of hasError.

You can do something more complex as well in stored procedures:

    DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
    BEGIN
        ...
    END;
Related