A stored procedure can contain generic condition handlers and specific condition handlers which handle specific SQLSTATE codes or specific conditions defined by condition names). If a stored procedure contains both specific condition handlers and a generic condition handler to handle similar conditions, the specific condition handlers take precedence. The following rules apply to such situations.
- When both SQLEXCEPTION and specific handlers for exception conditions are specified in a stored procedure.
What Raised Exception Matches Handler Action Any of the SQLSTATE values specified for a handler The action defined for the specific condition handler. Any of the condition names specified for a handler The action defined for the specific condition handler. No specific SQLSTATE code or condition name specified for any handler The action defined for the generic exception condition handler. - When both SQLWARNING and specific handlers for completion conditions are specified.
What Raised Exception Matches Handler Action Any of the SQLSTATE values specified for a handler The action defined for the specific condition handler. Any of the condition names specified for a handler The action defined for the specific condition handler. No specific SQLSTATE code or condition name specified for any handler The action defined for the generic completion condition handler. - When both NOT FOUND and specific handlers for “no data found” completion conditions are specified.
What SQLSTATE Value Matches Handler Action Any of the specific completion condition handlers The action defined for the specific completion condition handler. No specific condition handler The action defined for the generic NOT FOUND condition handler. - The completion condition “no data found” has precedence over the other generic completion conditions. Only a generic NOT FOUND handler or a specific condition handler can handle the “no data found” completion condition.