0
0
MySQLquery~10 mins

Error handling in procedures in MySQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a handler for SQL exceptions in a MySQL procedure.

MySQL
DECLARE CONTINUE HANDLER FOR [1] BEGIN SET @error_message = 'Error occurred'; END;
Drag options to blanks, or click blank then click option'
ANOT FOUND
BSQLEXCEPTION
CSQLWARNING
DSQLSTATE '02000'
Attempts:
3 left
💡 Hint
Common Mistakes
Using NOT FOUND instead of SQLEXCEPTION for general error handling.
Using SQLSTATE '02000' which is specific to 'no data' condition.
2fill in blank
medium

Complete the code to declare a handler that sets a flag when no data is found.

MySQL
DECLARE CONTINUE HANDLER FOR [1] SET no_data_flag = 1;
Drag options to blanks, or click blank then click option'
ASQLEXCEPTION
BSQLSTATE '45000'
CSQLWARNING
DNOT FOUND
Attempts:
3 left
💡 Hint
Common Mistakes
Using SQLEXCEPTION which catches all errors, not just 'no data'.
Using SQLSTATE '45000' which is a user-defined error.
3fill in blank
hard

Fix the error in the handler declaration to correctly catch warnings.

MySQL
DECLARE CONTINUE HANDLER FOR [1] SET warning_flag = TRUE;
Drag options to blanks, or click blank then click option'
ASQLSTATE '01000'
BWARNING
CSQLWARNING
DSQLSTATE 'HY000'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'WARNING' alone which is not a valid condition.
Using incorrect SQLSTATE codes for warnings.
4fill in blank
hard

Fill both blanks to declare a handler that sets an error message and exits the procedure on a custom error.

MySQL
DECLARE EXIT HANDLER FOR [1] BEGIN SET @error_msg = 'Custom error'; [2]; END;
Drag options to blanks, or click blank then click option'
ASQLSTATE '45000'
BLEAVE
CSQLEXCEPTION
DRETURN
Attempts:
3 left
💡 Hint
Common Mistakes
Using CONTINUE handler instead of EXIT for stopping execution.
Using LEAVE which is for loops, not procedures.
5fill in blank
hard

Fill all three blanks to declare a handler that logs an error code, sets a flag, and exits on any SQL exception.

MySQL
DECLARE EXIT HANDLER FOR [1] BEGIN SET @err_code = [2]; [3] = TRUE; END;
Drag options to blanks, or click blank then click option'
ASQLEXCEPTION
BSQLSTATE
Cerror_flag
DSQLWARNING
Attempts:
3 left
💡 Hint
Common Mistakes
Using SQLWARNING instead of SQLEXCEPTION for all errors.
Trying to assign error_flag without declaring it.