DataException

Overview

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.

Returned Types

ServoyException,

Constants Summarized

Type
Name
Summary

Exception code for ABSTRACT_FORM.

Exception code for ACQUIRE_LOCK_FAILURE.

Exception code for BAD_SQL_SYNTAX.

Exception code for CLIENT_NOT_AUTHORIZED.

Exception code for DATA_ACCESS_RESOURCE_FAILURE.

Exception code for DATA_INTEGRITY_VIOLATION.

Exception code for DEADLOCK.

Exception code for DELETE_NOT_GRANTED.

Exception code for EXECUTE_PROGRAM_FAILED.

Exception code for INCORRECT_LOGIN.

Exception code for INVALID_INPUT.

Exception code for INVALID_RESULTSET_ACCESS.

Exception code for MAINTENANCE_MODE.

Exception code for MUST_ROLLBACK.

Exception code for NO_ACCESS.

Exception code for NO_CREATE_ACCESS.

Exception code for NO_DELETE_ACCESS.

Exception code for NO_LICENSE.

Exception code for NO_MODIFY_ACCESS.

Exception code for NO_PARENT_DELETE_WITH_RELATED_RECORDS.

Exception code for NO_RELATED_CREATE_ACCESS.

Exception code for PERMISSION_DENIED.

Exception code for RECORD_LOCKED.

Exception code for RECORD_VALIDATION_FAILED.

Exception code for SAVE_FAILED.

Exception code for UNEXPECTED_UPDATE_COUNT.

Exception code for UNKNOWN_DATABASE_EXCEPTION.

Methods Summarized

Type
Name
Summary

Returns the error code for this ServoyException.

Returns the string message for this ServoyException.

Returns the parameters of the SQL query that caused this DataException in an array.

Returns the SQL query that caused this DataException.

Returns the SQLState for this DataException.

Returns the script stack trace for this ServoyException if this could be created.

Returns the stack trace for this ServoyException.

Returns the value for this DataException.

Returns the error code of the error thrown by the back-end database server.

Constants Detailed

ABSTRACT_FORM

Exception code for ABSTRACT_FORM.

This code is used when a form, that cannot be created, is shown (for example, a form without parts).

Type Number

Sample

//this sample script should be attached to onError method handler in the solution settings
application.output('Exception Object: '+ex)
application.output('MSG: '+ex.getMessage())
if (ex instanceof ServoyException)
{
	/** @type {ServoyException} */
	var servoyException = ex;
	application.output("is a ServoyException")
	application.output("Errorcode: "+servoyException.getErrorCode())
	var trace = "";
	if (ex.getScriptStackTrace) trace = servoyException.getScriptStackTrace();
	else if (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 save
		var array = databaseManager.getFailedRecords()
		for( var i = 0 ; i < array.length ; i++ )
		{
			var record = array[i];
			application.output(record.exception);
			if (record.exception instanceof DataException)
			{
				/** @type {DataException} */
				var dataException = record.exception;
				application.output('SQL: '+dataException.getSQL())
				application.output('SQLState: '+dataException.getSQLState())
				application.output('VendorErrorCode: '+dataException.getVendorErrorCode())
			}
		}
		return false
	}
}
//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 up
return true

ACQUIRE_LOCK_FAILURE

Exception code for ACQUIRE_LOCK_FAILURE.

This code is used when a database failed to lock a row or table.

Type Number

Sample

//this sample script should be attached to onError method handler in the solution settings
application.output('Exception Object: '+ex)
application.output('MSG: '+ex.getMessage())
if (ex instanceof ServoyException)
{
	/** @type {ServoyException} */
	var servoyException = ex;
	application.output("is a ServoyException")
	application.output("Errorcode: "+servoyException.getErrorCode())
	var trace = "";
	if (ex.getScriptStackTrace) trace = servoyException.getScriptStackTrace();
	else if (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 save
		var array = databaseManager.getFailedRecords()
		for( var i = 0 ; i < array.length ; i++ )
		{
			var record = array[i];
			application.output(record.exception);
			if (record.exception instanceof DataException)
			{
				/** @type {DataException} */
				var dataException = record.exception;
				application.output('SQL: '+dataException.getSQL())
				application.output('SQLState: '+dataException.getSQLState())
				application.output('VendorErrorCode: '+dataException.getVendorErrorCode())
			}
		}
		return false
	}
}
//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 up
return true

BAD_SQL_SYNTAX

Exception code for BAD_SQL_SYNTAX.

This code is used when a database exception is recognized as an sql syntax error.

Type Number

Sample

//this sample script should be attached to onError method handler in the solution settings
application.output('Exception Object: '+ex)
application.output('MSG: '+ex.getMessage())
if (ex instanceof ServoyException)
{
	/** @type {ServoyException} */
	var servoyException = ex;
	application.output("is a ServoyException")
	application.output("Errorcode: "+servoyException.getErrorCode())
	var trace = "";
	if (ex.getScriptStackTrace) trace = servoyException.getScriptStackTrace();
	else if (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 save
		var array = databaseManager.getFailedRecords()
		for( var i = 0 ; i < array.length ; i++ )
		{
			var record = array[i];
			application.output(record.exception);
			if (record.exception instanceof DataException)
			{
				/** @type {DataException} */
				var dataException = record.exception;
				application.output('SQL: '+dataException.getSQL())
				application.output('SQLState: '+dataException.getSQLState())
				application.output('VendorErrorCode: '+dataException.getVendorErrorCode())
			}
		}
		return false
	}
}
//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 up
return true

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.

Type Number

Sample

//this sample script should be attached to onError method handler in the solution settings
application.output('Exception Object: '+ex)
application.output('MSG: '+ex.getMessage())
if (ex instanceof ServoyException)
{
	/** @type {ServoyException} */
	var servoyException = ex;
	application.output("is a ServoyException")
	application.output("Errorcode: "+servoyException.getErrorCode())
	var trace = "";
	if (ex.getScriptStackTrace) trace = servoyException.getScriptStackTrace();
	else if (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 save
		var array = databaseManager.getFailedRecords()
		for( var i = 0 ; i < array.length ; i++ )
		{
			var record = array[i];
			application.output(record.exception);
			if (record.exception instanceof DataException)
			{