Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
In production applications, unhandled database errors (such as duplicate key violations, foreign key constraints, or connection drops) can cause procedures to crash mid-execution, leaving transactions dangling.
MySQL provides robust error handling through DECLARE ... HANDLER statements and the RESIGNAL command.
CONTINUE: Executes the handler statement and continues procedure execution at the next statement.EXIT: Executes the handler statement and immediately terminates execution of the enclosing BEGIN ... END block.SQLEXCEPTION: Catches any general SQL error (codes not starting with 00, 01, or 02).SQLWARNING: Catches warnings.NOT FOUND: Triggers when a cursor reaches the end of data or a SELECT INTO returns zero rows.1062 (Duplicate Key Entry).Consider a procedure that inserts a user and customer profile atomically. If duplicate email error 1062 occurs, it automatically rolls back and outputs an error message:
You can raise custom business errors using SIGNAL SQLSTATE:
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Control Flow: Variables, Branches & Loops | Creating User-Defined Functions (CREATE FUNCTION) |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.