try..catch blocks

Hello,

When the attached code is executed, an error is thrown on the controller.saveData() method. This is because the primary key has a duplicate value.

Instead of going to the catch block, servoy displays an messagebox with an error on the screen. The method that calls this code thinks it executes okay…

What I want is that the method that calls this code knows that there was an error creating the record! Does anybody know a sollution or work-around for this problem?

Thanks,

Anton

try
{
	controller.newRecord( false )
	
	try
	{
		contactid = arguments[0]
		relatieid = arguments[1]
	
		//create bug... set duplicate pk
		relcpid = 7;
		
		controller.saveData();
	}
	catch( error )
	{
		controller.deleteRecord();
		throw error;
	}
}
catch( error )
{
	throw error;
}

we can’t throw that error all the way down currently because then the normal save/newrecord behaviour outside a script wouldn’t work at all.

Maybe we can fix this with application.getLastErrorCode() ect.
Have to check this out.

Hello Johan,

Thanks for your reply.

Is there an alternative that I can use now to read or catch errors that occured in the data-layer?

Anton

At the moment you’d do a pre-validation instead of post (by catching the error). We plan to support post in the future.

What are try, catch and throw? I can’t seem to find them in the SOM.

Just looking for a pointer to documentation here.

Chris,

TRY and CATCH are Javascript Error Handling objects. When you write Javascript code (and other languages) you use TRY/CATCH to see if there was an error during execution.