Try { } to Catch { } error on dataset

Hi,

I would like to try to catch an error on getDataSetByQuery

	_query = 'SELECT * from myTable where col1=? and col2=?'
	try
	{
		_ds = databaseManager.getDataSetByQuery('myServer' ,_query, [_arg1, _arg2], -1)
	}
	catch (e)
	{
		_message = e.getMessage();
	}

For example if the table doesn’t exist or an other error in the query

When I put a global method in the onError property on the solution, then I get the error in the errorhandler
When I don’t put a global method as errorhandler AND I don’t use the try{} catch{}, then the error appears in a pop-up message and also in the console within developer.

But in this case I don’t want to use the errorhandler, but want to use try/catch and would like to have the errormessage as result.

There isn’t a foundset involved here, so there are no failedRecords, so I can’t check the exception of records.
And I can’t either use the

_message = _ds.getException()

because the result is not a JSDataset.

So how can I get the errormessage in this case?
I would have expected that the catch{e} has e as argument and I find the message as property of e, but that is also not the case.

What else can I do, except to put in my catch{} part

_message = 'Query failed'

without knowing for what reason the query failed.

I do something similar in my solution and I’m able to get the error message successfully:

try {
		var dataset = databaseManager.getDataSetByQuery(globals.connectionName, query, null, maxReturnedRows);
	}
	catch (err) {		
		plugins.dialogs.showErrorDialog("SQL Error","There was an error in the SQL statement.\n Database Error: "+err.javaException.getCause().getMessage(),"Okay")
		return;
	}

Maybe this is 5.1 functionality? I work with 4.1.5

I think once you use a global onError method, you cannot do what you want. I have the same problem here…

It works also in 4.1.5

Great!

Just you need to know a lot about Java(script) to know that this is possible

In 3.5 that does not work…

In 3.5 that does not work…

Correct: in 3.5 a faulty query wouldn’t raise an error. You needed to check the exceptionMessage yourself (forgot the name of the function/property on the JSDataSet to do so).

As of 4.0.1 this changed (see release notes: http://forum.servoy.com/viewtopic.php?f=16&t=11083).

Paul