I wrote an errorhandler (which is registered as onError method in the Solution Settings). The errorhandler was written like the example in the Servoy manual:
var _e = arguments[0];
var _message = _e.getMessage();
var _errorcode = _e.getErrorCode();
var _dialogmessage
var _form = application.getMethodTriggerFormName()
var _element = application.getMethodTriggerElementName()
application.output('Errorhandler: Exception=' + _e);
application.output('Errorhandler: Form=' + _form);
application.output('Errorhandler: Element=' + _element);
if (_e.isServoyException)
{
application.output('Errorhandler: isServoyException')
application.output('Errorhandler: Errorcode=' +_errorcode)
application.output('Errorhandler: Message=' + _message)
_dialogmessage = 'Some error was detected. Please make a screenshot of this screen and send it to me.\n\n'
_dialogmessage += 'Errorcode=' + _errorcode + '\n'
_dialogmessage += 'Errormsg=' + _message + '\n'
_dialogmessage += 'Form=' + _form + '\n'
_dialogmessage += 'Element=' + _element + '\n'
// If in transaction, then rollback the transaction
if (databaseManager.hasTransaction())
{
databaseManager.rollbackTransaction()
}
plugins.dialogs.showErrorDialog( 'Error', _dialogmessage, 'OK');
}
continued ...
I’m getting an error that the line
var _errorcode = _e.getErrorCode();
is invalid, because getErrorCode() is an invalid function, but in the Servoy manual it is used in the same way (page 472 Developer Reference Guide)
Anyone knows something about writing errorhandlers?
Am I doing something wrong?
I noticed also that the errorhandler is not always being called when I expected it (like on database errors)
hmm, I wanted to be sure that you are working with the latest version.
Unfortunately I am not that familiar with error handlers in Servoy to confirm that there is an issue.
I use the following error method with 3.5.2 and Oracle 10g.
Works fine !!
However i noticed that the solution error method is not called if you use transactions. I filed a case for this problem a while ago.
//this sample script should be attached to onError method handler in the solution settings
application.output('In error Trap');
var e = arguments[0];
application.output("Exception Object: " + e)
application.output("MSG: " + e.getMessage())
if (e.isServoyException)
{
application.output("is a ServoyException")
application.output("Errorcode: "+e.getErrorCode())
if (e.getErrorCode() == ServoyException.INVALID_INPUT)
{
application.beep()
if (globals.validate_message == '--')
{
var thePressedButton = plugins.dialogs.showErrorDialog('Invalid Value', 'Veld mag niet leeg zijn !','OK');
globals.validate_message = '--'
}
else
{
var thePressedButton = plugins.dialogs.showErrorDialog('Invalid Value', globals.validate_message,'OK');
globals.validate_message = '--'
}
}
if (e.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.isDataException)
{
application.output("SQL: "+record.exception.getSQL())
application.output("SQLState: "+record.exception.getSQLState())
application.output("VendorErrorCode: "+record.exception.getVendorErrorCode())
}
}
}
}