Error trapping

I am testing the error trapping function in Servoy.

set the following (standard) method in the Solution Settings Error Method :

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.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())
		  }
	  }
  }
}

tested it by violating a unique key constraint.

Works fine in “autosave mode”.

However when i am violating the same unique key within a transaction

the method does not get fired.

Anyone has experience with this ??

Hans Nieuwenhuis:
tested it by violating a unique key constraint.

Works fine in “autosave mode”.

However when i am violating the same unique key within a transaction

the method does not get fired.

Anyone has experience with this ??

Are you sure error messages are fired by the db when you’re inside a transaction? I mean, it could be something related to db behaviour rather than Servoy’s error message handling…

Yes i am sure,

in both cases i can see an (different) error in te server administration log

in case of “Autosave” :

com.servoy.j2db.dataprocessing.DataException: ORA-00001: unique constraint (BERP.UI_SITE_CODE) violated 
     at com.servoy.j2db.dblayer.DBDependentHandler.a(Unknown Source) 
     at com.servoy.j2db.persistence.Server.translateSQLException(Unknown Source) 
     at com.servoy.j2db.dataprocessing.SQLEngine.performUpdates(Unknown Source) 
     at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(Unknown Source) 
     at com.servoy.j2db.FormController.valueChanged(Unknown Source) 
     at com.servoy.j2db.util.gui.v.a(Unknown Source) 
     at com.servoy.j2db.util.gui.v.a(Unknown Source) 
     at com.servoy.j2db.util.gui.v.a(Unknown Source) 
     at com.servoy.j2db.util.gui.FixedJTable.editCellAt(Unknown Source) 
     at javax.swing.plaf.basic.BasicTableUI$Handler.adjustSelection(Unknown Source) 
     at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(Unknown Source) 
     at java.awt.AWTEventMulticaster.mousePressed(Unknown Source) 
     at java.awt.AWTEventMulticaster.mousePressed(Unknown Source) 
     at java.awt.Component.processMouseEvent(Unknown Source) 
     at javax.swing.JComponent.processMouseEvent(Unknown Source) 
     at java.awt.Component.processEvent(Unknown Source) 
     at java.awt.Container.processEvent(Unknown Source) 
     at java.awt.Component.dispatchEventImpl(Unknown Source) 
     at java.awt.Container.dispatchEventImpl(Unknown Source) 
     at java.awt.Component.dispatchEvent(Unknown Source) 
     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
     at java.awt.Container.dispatchEventImpl(Unknown Source) 
     at java.awt.Window.dispatchEventImpl(Unknown Source) 
     at java.awt.Component.dispatchEvent(Unknown Source) 
     at java.awt.EventQueue.dispatchEvent(Unknown Source) 
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
     at java.awt.EventDispatchThread.run(Unknown Source)  
2007-06-24 19:19 AWT-EventQueue-0 ERROR com.servoy.j2db.util.Debug Throwable 
java.sql.SQLException: ORA-00001: unique constraint (BERP.UI_SITE_CODE) violated 
     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) 
     at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331) 
     at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288) 
     at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743) 
     at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213) 
     at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:952) 
     at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1160) 
     at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285) 
     at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
     at java.lang.reflect.Method.invoke(Unknown Source) 
     at com.servoy.j2db.persistence.datasource.p.invoke(Unknown Source) 
     at $Proxy1.executeUpdate(Unknown Source) 
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207) 
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207) 
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207) 
     at com.servoy.j2db.dataprocessing.SQLEngine.performUpdates(Unknown Source) 
     at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(Unknown Source) 
     at com.servoy.j2db.FormController.valueChanged(Unknown Source) 
     at com.servoy.j2db.util.gui.v.a(Unknown Source) 
     at com.servoy.j2db.util.gui.v.a(Unknown Source) 
     at com.servoy.j2db.util.gui.v.a(Unknown Source) 
     at com.servoy.j2db.util.gui.FixedJTable.editCellAt(Unknown Source) 
     at javax.swing.plaf.basic.BasicTableUI$Handler.adjustSelection(Unknown Source) 
     at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(Unknown Source) 
     at java.awt.AWTEventMulticaster.mousePressed(Unknown Source) 
     at java.awt.AWTEventMulticaster.mousePressed(Unknown Source) 
     at java.awt.Component.processMouseEvent(Unknown Source) 
     at javax.swing.JComponent.processMouseEvent(Unknown Source) 
     at java.awt.Component.processEvent(Unknown Source) 
     at java.awt.Container.processEvent(Unknown Source) 
     at java.awt.Component.dispatchEventImpl(Unknown Source) 
     at java.awt.Container.dispatchEventImpl(Unknown Source) 
     at java.awt.Component.dispatchEvent(Unknown Source) 
     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
     at java.awt.Container.dispatchEventImpl(Unknown Source) 
     at java.awt.Window.dispatchEventImpl(Unknown Source) 
     at java.awt.Component.dispatchEvent(Unknown Source) 
     at java.awt.EventQueue.dispatchEvent(Unknown Source) 
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
     at java.awt.EventDispatchThread.run(Unknown Source)

in case of transaction :

java.sql.SQLException: ORA-00001: unique constraint (BERP.UI_SITE_CODE) violated 
     at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) 
     at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331) 
     at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288) 
     at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743) 
     at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:213) 
     at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:952) 
     at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1160) 
     at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285) 
     at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
     at java.lang.reflect.Method.invoke(Unknown Source) 
     at com.servoy.j2db.persistence.datasource.p.invoke(Unknown Source) 
     at $Proxy1.executeUpdate(Unknown Source) 
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207) 
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207) 
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:207) 
     at com.servoy.j2db.dataprocessing.SQLEngine.performUpdates(Unknown Source) 
     at com.servoy.j2db.dataprocessing.EditRecordList.stopEditing(Unknown Source) 
     at com.servoy.j2db.dataprocessing.FoundSetManager.commitTransaction(Unknown Source) 
     at com.servoy.j2db.dataprocessing.JSDatabaseManager.js_commitTransaction(Unknown Source) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
     at java.lang.reflect.Method.invoke(Unknown Source) 
     at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:334) 
     at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1254) 
     at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2031) 
     at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:94) 
     at com.servoy.j2db.scripting.e.call(Unknown Source) 
     at org.mozilla.javascript.ScriptRuntime.call(ScriptRuntime.java:1254) 
     at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2031) 
     at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:94) 
     at com.servoy.j2db.scripting.e.call(Unknown Source) 
     at com.servoy.j2db.develop.debugger.k.a(Unknown Source) 
     at com.servoy.j2db.develop.debugger.k.executeFunction(Unknown Source) 
     at com.servoy.j2db.FormController.a(Unknown Source) 
     at com.servoy.j2db.FormController.executeFunction(Unknown Source) 
     at com.servoy.j2db.FormController.actionPerformed(Unknown Source) 
     at com.servoy.j2db.FormController$a.actionPerformed(Unknown Source) 
     at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
     at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) 
     at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) 
     at javax.swing.DefaultButtonModel.setPressed(Unknown Source) 
     at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) 
     at java.awt.Component.processMouseEvent(Unknown Source) 
     at javax.swing.JComponent.processMouseEvent(Unknown Source) 
     at java.awt.Component.processEvent(Unknown Source) 
     at java.awt.Container.processEvent(Unknown Source) 
     at java.awt.Component.dispatchEventImpl(Unknown Source) 
     at java.awt.Container.dispatchEventImpl(Unknown Source) 
     at java.awt.Component.dispatchEvent(Unknown Source) 
     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
     at java.awt.Container.dispatchEventImpl(Unknown Source) 
     at java.awt.Window.dispatchEventImpl(Unknown Source) 
     at java.awt.Component.dispatchEvent(Unknown Source) 
     at java.awt.EventQueue.dispatchEvent(Unknown Source) 
     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
     at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
     at java.awt.EventDispatchThread.run(Unknown Source)

[/list]

Seem to be able to trap it using the following code in the method that does the actual save :

	databaseManager.commitTransaction()
	databaseManager.releaseAllLocks()

//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);
}

But i am not sure that this is the way to do it.

I think the general error trapping defined in the Solution Settings should trap this error.

Or am i missing something ??

Created a case in the Support System with an example application and log files.