Error Handling Best Practice

Hello,

Is there any best practice for error trapping in Servoy. Obviously, pre and post validation can be checked at field level. I know you can catch sql errors with the 4 error codes.

I was thinking in the terms of Try..catch.

If errorcode == ? then do something.

Is there a list of generic error codes that servoy will return that you can trap?
Or is general field validation enough?

Thanks for any comments.

Try/Catch works great (but it would be nice if exception commands were in the application node of the editor along with nice samples as per the norm).

Here’s an example that I use in a global method to handle all controller buttons. Now that I am using modules, I wanted an easy way to handle the case where a module is missing without having to hard code the controller that has buttons to each form. I just give each button a name equal to the form I want to load.

// show the form by button name
try {
	forms[application.getMethodTriggerElementName()].controller.show();
}

//catch the exception if the form is missing - no module
catch(ex) {

	//show dialog
	var thePressedButton = plugins.dialogs.showErrorDialog( 'Module Error','<html><b>Sorry, that module is not yet installed.</b><p>Conversion Error</html>'
,'OK');

}

In this example, I’m only handling “Conversion Errors” because that’s what I get when the form is missing. You could read the value of ‘ex’ here and with an if of switch and handle the exceptions however you want.

Bob,

Thanks for example.

Clarifies things nicely.

Cheers