Challenge - 5 Problems
Error Handling Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of a procedure with DECLARE CONTINUE HANDLER
Consider the following MySQL procedure. What will be the output when calling
CALL test_error_handling();?MySQL
DELIMITER $$ CREATE PROCEDURE test_error_handling() BEGIN DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN SELECT 'Error caught'; END; -- This will cause a division by zero error SELECT 10 / 0; SELECT 'No error'; END$$ DELIMITER ;
Attempts:
2 left
💡 Hint
Think about what DECLARE CONTINUE HANDLER does when an error occurs inside the procedure.
✗ Incorrect
The DECLARE CONTINUE HANDLER catches the division by zero error and runs the handler block, which outputs 'Error caught'.
🧠 Conceptual
intermediate1:30remaining
Purpose of DECLARE EXIT HANDLER in MySQL procedures
What is the main difference between a DECLARE CONTINUE HANDLER and a DECLARE EXIT HANDLER in MySQL stored procedures?
Attempts:
2 left
💡 Hint
Think about what happens to the procedure flow after the handler runs.
✗ Incorrect
A CONTINUE HANDLER lets the procedure continue after the handler code runs, while an EXIT HANDLER causes the procedure to exit immediately after the handler code executes.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this error handler declaration
Which option correctly fixes the syntax error in this MySQL procedure snippet?
MySQL
CREATE PROCEDURE sample_proc() BEGIN DECLARE HANDLER FOR SQLEXCEPTION BEGIN SELECT 'Error'; END; END;
Attempts:
2 left
💡 Hint
MySQL requires a handler type keyword before HANDLER.
✗ Incorrect
MySQL requires the handler type (CONTINUE or EXIT) before HANDLER. Omitting it causes a syntax error.
🔧 Debug
advanced2:30remaining
Why does this procedure not catch the error as expected?
Given this procedure, why does the error not get caught by the handler?
MySQL
DELIMITER $$ CREATE PROCEDURE test_proc() BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN SELECT 'Error caught'; END; SET @x = 1/0; SELECT 'No error'; END$$ DELIMITER ;
Attempts:
2 left
💡 Hint
Consider where the error happens and how MySQL evaluates expressions.
✗ Incorrect
Division by zero in a SET statement assigning to a user variable raises only a warning (SQLWARNING), not SQLEXCEPTION, so the handler does not trigger.
❓ optimization
expert3:00remaining
Optimizing error handling for multiple error codes
You want to catch multiple specific SQL error codes in a MySQL procedure and handle them differently. Which approach is the most efficient and correct?
Attempts:
2 left
💡 Hint
MySQL allows multiple handlers for different conditions.
✗ Incorrect
Declaring multiple handlers for specific error codes lets you handle each error precisely and efficiently without extra checks inside the handler.