# Exception Errorhandling

**URL:** https://forum.servoy.com/t/exception-errorhandling/8390
**Category:** Classic Servoy
**Created:** [November 12, 2007, 10:03am UTC](https://forum.servoy.com/t/exception-errorhandling/8390 "2007-11-12T10:03:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)
#### Post date: [November 12, 2007, 10:03am UTC](https://forum.servoy.com/t/exception-errorhandling/8390/1 "2007-11-12T10:03:00Z")

</div>

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:

```auto
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

```auto
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)

---

<div class="post-metadata">

### Author: ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)
#### Post date: [November 12, 2007, 10:22am UTC](https://forum.servoy.com/t/exception-errorhandling/8390/2 "2007-11-12T10:22:26Z")

</div>

Which Servoy version are you using?

---

<div class="post-metadata">

### Author: ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)
#### Post date: [November 12, 2007, 10:25am UTC](https://forum.servoy.com/t/exception-errorhandling/8390/3 "2007-11-12T10:25:43Z")

</div>

> Which Servoy version are you using?

3.5.2 with SQL Server 2005 database

---

<div class="post-metadata">

### Author: ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)
#### Post date: [November 12, 2007, 10:38am UTC](https://forum.servoy.com/t/exception-errorhandling/8390/4 "2007-11-12T10:38:16Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Hans\_Nieuwenhuis](https://avatars.discourse-cdn.com/v4/letter/h/87869e/32.png) [@Hans\_Nieuwenhuis](https://forum.servoy.com/u/Hans_Nieuwenhuis)
#### Post date: [November 12, 2007, 4:55pm UTC](https://forum.servoy.com/t/exception-errorhandling/8390/5 "2007-11-12T16:55:19Z")

</div>

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.

```auto
//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())
		  }
	  }
  }
}

```

---

<div class="post-metadata">

### Author: ![martinh](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@martinh](https://forum.servoy.com/u/martinh)
#### Post date: [November 13, 2007, 8:23am UTC](https://forum.servoy.com/t/exception-errorhandling/8390/6 "2007-11-13T08:23:47Z")

</div>

> 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.

That is important info. Indeed I use transactions.  
That explains why I don’t have my errormessage triggered, what I discussed in another topic

> **[Errormessages from database](https://forum.servoy.com/viewtopic.php?t=9077)**
>
> I would like to know how I can show an error that is triggered by the database. I have the following coding: \_success = forms\[\_form\].controller.saveData(); if (\_success == false) { \_errormessage = ServoyException.getMessage(); ...
