Related Documentation Download this Manual
PDF (US Ltr) - 41.2Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb
MySQL 9.4 Reference Manual / ... / Stored Objects / JavaScript Stored Programs / JavaScript SQL API / SqlError Object
When anSqlError is thrown, an error is raised in MySQL similar to how one is raised by aSIGNAL statement. You can create anSqlError using the constructor shown here:
new SqlError(sql_state: Number,message: String,error_number: Number) The JavaScript stored procedure in the following example tries and throws anSqlError created using this constructor. Invoking the procedure raises the error, as can be seen here:
mysql> CREATE PROCEDURE test_catch_throw_signal() LANGUAGE JAVASCRIPT -> AS $$ $> console.clear() $> try { $> throw new mysql.SQLError(45000, 'Some error', 1001) $> } catch (e) { $> console.log(e) $> } $> $$;Query OK, 0 rows affected (0.02 sec)mysql> CALL test_catch_throw_signal();Query OK, 0 rows affected (0.04 sec)mysql> SELECT mle_session_state("stdout")\G*************************** 1. row ***************************org.graalvm.polyglot.nativeapi.PolyglotNativeAPI$CallbackException: SQL-CALLOUT: Error code: 1001 Error state: 45000 Error message: `Some error`1 row in set (0.00 sec)sql_state anderror_number must be of typeNumber. MLE throws an exception if either of these values isInfinity orNaN.
You can also invokeSIGNAL from JavaScript routine code to throw an exception, similar to what is shown here:
mysql> CREATE PROCEDURE test_signal_no_catch() LANGUAGE JAVASCRIPT -> AS $$ $> console.clear() $> session.runSql("SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT= 'Some error', MYSQL_ERRNO = 1000") $> $$;Query OK, 0 rows affected (0.01 sec)mysql> CALL test_signal_no_catch();ERROR 1000 (45000): Some errorRelated Documentation Download this Manual
PDF (US Ltr) - 41.2Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb
PDF (A4) - 41.3Mb
Man Pages (TGZ) - 262.8Kb
Man Pages (Zip) - 368.8Kb
Info (Gzip) - 4.1Mb
Info (Zip) - 4.1Mb