Designed for handling SQL-related errors, DataException offers detailed methods to inspect the root causes of database issues. It exposes properties like the SQL query, SQL state, vendor error code, and associated parameters for debugging. Deprecated methods maintain compatibility with older implementations, while scripting-friendly features simplify usage in client-side logic.
//this sample script should be attached to onError method handler in the solution settingsapplication.output('Exception Object: '+ex)application.output('MSG: '+ex.getMessage())if (ex instanceofServoyException){/** @type{ServoyException} */var servoyException = ex;application.output("is a ServoyException")application.output("Errorcode: "+servoyException.getErrorCode())var trace ="";if (ex.getScriptStackTrace) trace =servoyException.getScriptStackTrace();elseif (servoyException.getStackTrace) trace =servoyException.getStackTrace();if (servoyException.getErrorCode() ==ServoyException.SAVE_FAILED) {plugins.dialogs.showErrorDialog( 'Error','It seems you did not fill in a required field','OK');//Get the failed records after a savevar array =databaseManager.getFailedRecords()for( var i =0 ; i <array.length ; i++ ) {var record = array[i];application.output(record.exception);if (record.exception instanceofDataException) {/** @type{DataException} */var dataException =record.exception;application.output('SQL: '+dataException.getSQL())application.output('SQLState: '+dataException.getSQLState())application.output('VendorErrorCode: '+dataException.getVendorErrorCode()) } }returnfalse }}//if returns false or no return, error is not reported to client; if returns true error is reported//by default error report means logging the error, in smart client an error dialog will also show upreturntrue
ACQUIRE_LOCK_FAILURE
Exception code for ACQUIRE_LOCK_FAILURE.
This code is used when a database failed to lock a row or table.
//this sample script should be attached to onError method handler in the solution settingsapplication.output('Exception Object: '+ex)application.output('MSG: '+ex.getMessage())if (ex instanceofServoyException){/** @type{ServoyException} */var servoyException = ex;application.output("is a ServoyException")application.output("Errorcode: "+servoyException.getErrorCode())var trace ="";if (ex.getScriptStackTrace) trace =servoyException.getScriptStackTrace();elseif (servoyException.getStackTrace) trace =servoyException.getStackTrace();if (servoyException.getErrorCode() ==ServoyException.SAVE_FAILED) {plugins.dialogs.showErrorDialog( 'Error','It seems you did not fill in a required field','OK');//Get the failed records after a savevar array =databaseManager.getFailedRecords()for( var i =0 ; i <array.length ; i++ ) {var record = array[i];application.output(record.exception);if (record.exception instanceofDataException) {/** @type{DataException} */var dataException =record.exception;application.output('SQL: '+dataException.getSQL())application.output('SQLState: '+dataException.getSQLState())application.output('VendorErrorCode: '+dataException.getVendorErrorCode()) } }returnfalse }}//if returns false or no return, error is not reported to client; if returns true error is reported//by default error report means logging the error, in smart client an error dialog will also show upreturntrue
BAD_SQL_SYNTAX
Exception code for BAD_SQL_SYNTAX.
This code is used when a database exception is recognized as an sql syntax error.
//this sample script should be attached to onError method handler in the solution settingsapplication.output('Exception Object: '+ex)application.output('MSG: '+ex.getMessage())if (ex instanceofServoyException){/** @type{ServoyException} */var servoyException = ex;application.output("is a ServoyException")application.output("Errorcode: "+servoyException.getErrorCode())var trace ="";if (ex.getScriptStackTrace) trace =servoyException.getScriptStackTrace();elseif (servoyException.getStackTrace) trace =servoyException.getStackTrace();if (servoyException.getErrorCode() ==ServoyException.SAVE_FAILED) {plugins.dialogs.showErrorDialog( 'Error','It seems you did not fill in a required field','OK');//Get the failed records after a savevar array =databaseManager.getFailedRecords()for( var i =0 ; i <array.length ; i++ ) {var record = array[i];application.output(record.exception);if (record.exception instanceofDataException) {/** @type{DataException} */var dataException =record.exception;application.output('SQL: '+dataException.getSQL())application.output('SQLState: '+dataException.getSQLState())application.output('VendorErrorCode: '+dataException.getVendorErrorCode()) } }returnfalse }}//if returns false or no return, error is not reported to client; if returns true error is reported//by default error report means logging the error, in smart client an error dialog will also show upreturntrue
CLIENT_NOT_AUTHORIZED
Exception code for CLIENT_NOT_AUTHORIZED.
This code is used when an client performs an action that requires the user to be logged in and the user has not logged in yet.
//this sample script should be attached to onError method handler in the solution settingsapplication.output('Exception Object: '+ex)application.output('MSG: '+ex.getMessage())if (ex instanceofServoyException){/** @type{ServoyException} */var servoyException = ex;application.output("is a ServoyException")application.output("Errorcode: "+servoyException.getErrorCode())var trace ="";if (ex.getScriptStackTrace) trace =servoyException.getScriptStackTrace();elseif (servoyException.getStackTrace) trace =servoyException.getStackTrace();if (servoyException.getErrorCode() ==ServoyException.SAVE_FAILED) {plugins.dialogs.showErrorDialog( 'Error','It seems you did not fill in a required field','OK');//Get the failed records after a savevar array =databaseManager.getFailedRecords()for( var i =0 ; i <array.length ; i++ ) {var record = array[i];application.output(record.exception);if (record.exception instanceofDataException) {