cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

MobiLink: Sending error messages from Java Sychronization Script

2,824

Hello,

we are using SQL Anywhere and MobiLink 16.0.0.2052.

We wrote a Java based synchronization script for the prepare_download event. In our Java method we are doing some validation, which sometimes lead to Java Exception.

When this happens, we get a sync failed on the client. That is the behaviour that we would expect. However it would be more elegant to catch the exception instead and send a meaningful error message to the client and the user.

I checked the dcx side, but could not find something about forcefully letting a sync fail and sending error messages to the client. Any idea how this can be done?

Thanks and best regards, Alex

Accepted Solutions (0)

Answers (3)

Answers (3)

The modify_error_message script is invoked only for SQL errors, so it won't get triggered for Java exceptions.

On v12 and earlier you could return a SQL string from your Java script that will raise an error and then use the modify_error_message to change that message to what you want.

Alternatively, you could create table that you log the errors to. Then you can create a separate publication that you use to download the error if a sync fails. This would work on all version of the server. Edit: This has to be done on a connection returned by ServerContext.makeConnection(), since the connection returned by DBContext.getConnection will be rolled back when the prepare_for_download script fails.

This is a feature that customers and internal users have asked for, but I haven't had time to get around to fixing it. It's something that I would like to change, but I can't make any promises as to when or which versions.

Former Member

There is another option. You can use the modify_error_message script. See the documentation here.

Former Member
0 Kudos

As Bill answered, the modify_error_message script is only invoked for SQL errors. If a Java script causes a SQL error, it causes a SQLException in the Java script, not a SQL error visible to the MobiLink server.

VolkerBarth
Contributor
0 Kudos

Have you had a look at the following doc topics:

Basically, you will have to set the action_code value.