Scope:
1. Include the statements in begni... end;
Declare continue handler for 1048 SELECT 'attempt to insert a null value ';
BEGIN
Insert into a VALUES (6, NULL );
END;
If the second field of Table a is not empty, the 1048 error is triggered.
2. If the error processing is defined in begin... end, other statements will not trigger the error.BEGIN
BEGIN
Declare continue handler for 1216 select
'Foreign key constraint violated ';
END;
Insert into orders ments (department_name, manager_id, location)
VALUES ('elbonian hr', 'catbert ', 'catbertia ');
END;
3. capture errors thrown by other stored procedures
Priority:
You can define multiple handler in a begin... end block to handle different exceptions respectively. For example:
Declare exit handler for sqlexception
Begin
Select 'error ';
End;
DECLARE continue handler for sqlstate '000000' SET done = 1;
The processing priority is:
MySQL Error code> SQLSTATE code> naming ConditionsMySQL error code, for example 1062
ANSI standard SQLSTATE code, for example 23000
Naming conditions, such as NOT FOUND