query_script_throw

throw: throw an exception

SYNOPSIS

statement;
if (expression)
  throw 'message';
statement;

DESCRIPTION

throw is a QueryScript statement which, when invoked, raises an error.

When executed from within a try statement, flow resumes at the matching catch block.

Otherwise, it makes for the (ungraceful) termination of the script's execution. If an active transaction is in place, it is rolled back.

throw takes a text parameter, which is the error message. It is stored in the @common_schema_error variable.

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

EXAMPLES

Throw, get the error message:

set @x := 3;
while (@x > 0)
{
  set @x := @x - 1;
  if (@x = 1)
    throw 'x is too low!';
}

ERROR 1644 (91100): x is too low!

mysql> select @common_schema_error;
+----------------------+
| @common_schema_error |
+----------------------+
| 'x is too low!'      |
+----------------------+

SEE ALSO

Flow control, try-catch, return

AUTHOR

Shlomi Noach
 
common_schema documentation