there are several declarative forms of error handling: § If any errors (not notFOUND), set L_error to1to continue execution after:DECLARE CONTINUEHANDLER forSQLEXCEPTIONSETL_error=1§ If any errors occur (not notFOUND), executes rollback and generates an error message after exiting the current block or stored procedure. DECLARE EXITHANDLER forSQLEXCEPTIONBEGIN ROLLBACK; SELECT 'Error occurred–terminating'; END§ If the MySQL 1062 error (Duplicate health value) occurs, execute the SELECT statement (sending a message to the caller) after executionDECLARE CONTINUEHander for 1062 SELECT 'Duplicate key in index'§ If the SQLSTATE 2300 error (Duplicate health value) occurs, execute the SELECT statement (sending a message to the calling program)DECLARE CONTINUEHander forSQLSTATE'23000' SELECT 'Duplicate key in index'§ When the cursor or SQL SELECT statement does not return a value, set the L_done=1continue execution afterDECLARE CONTINUEHANDLER for notFOUNDSETL_done=1This example, in addition to using the SQLSTATE variable instead of a naming condition, is the same as in the previous exampleDECLARE CONTINUEHANDLER forSQLSTATE'02000' SETL_done=1in this example, in addition to using MySQL's error code variables instead of naming conditions or SQLSTATE variables, the first two examplesDECLARE CONTINUEHANDLER for 1329 SETL_done=1;
MySQL Error handling