throw

NAME

throw(): Disrupt execution with error

TYPE

Procedure

DESCRIPTION

Issues an error at the point of invocation, providing with an error message.

This is done by invoking an invalid command on the server. The result of such invocation will break execution of calling code. If this routine is invoked from another routine, the entire call stack is aborted. If this routine is called during a transaction, the transaction aborts and rolls back.

On a MySQL >= 5.5 server this routine calls upon SIGNAL. On a 5.1 server it generates a statement which reads from an invalid table, producing an awkward yet informative error message.

SYNOPSIS

throw(error_message VARCHAR(1024) CHARSET utf8)
  NO SQL

Input:

  • error_message: a message to be displayed within error statement.

Output:

  • @common_schema_error: The procedure sets this variable to the error_message supplied.

EXAMPLES

Invoke throw() directly, on a 5.1 MySQL server:

mysql> call throw('Unknown variable type');
ERROR 1644 (91100): Unknown variable type

mysql> SELECT @common_schema_error;
+-----------------------+
| @common_schema_error  |
+-----------------------+
| Unknown variable type |
+-----------------------+

Invoke throw() directly, on a 5.1 MySQL server:

mysql> call throw('Unknown variable type');
ERROR 1146 (42S02): Table 'error.Unknown variable type' doesn't exist

Invoke a syntactically invalid script; the run() routine and subroutines validate script syntax and call upon throw():

mysql> call run('{set @x := 3; ; ; }');
ERROR 1103 (42000): Incorrect table name 'QueryScript error: [Empty statement not allowed. Use {} instead] at 16: "; ; }"'

mysql> SELECT @common_schema_error;
+---------------------------------------------------------------------------------+
| @common_schema_error                                                            |
+---------------------------------------------------------------------------------+
| QueryScript error: [Empty statement not allowed. Use {} instead] at 16: "; ; }" |
+---------------------------------------------------------------------------------+

ENVIRONMENT

MySQL 5.1 or newer

AUTHOR

Shlomi Noach
 
common_schema documentation