ex in Catch(ex) is not recognized

Hi,

I’m new to the Servoy exception handling, but its known to me in dotNET

So, I’m strugglng with the argument of Catch in the try catch finally block:

On application level scope it is seen ( in the onError event)

But it is unseen in local block, e.g.

try {                                   
        stuff.....		
} 
catch (ex) { 
         .....
        var myfirst_msg = ex.getMessage();
        application.output(myfirst_msg); 
}

There is nothing in ex, why… ?

PS I tried:
var ex = new ServoyException;

in the method but to no result ( i thik this is not the way to go also…)

ex should be there just fine, you use that code that i see above?
what goes wrong then? the application.output(myfirst_msg) is hit?
Then ex does exists just fine because else you would get a error on ex.getMessage()

the problem is that you won’t see ex in the debugger, this is a limitation of the rhino debugger, not something that servoy can fix so easily.

OK,
is it that?..
Initially, i - indeed- just looked in the Expressions view.

But is remaining problem ex = null

So after a run i get:

TypeError: Cannot find function getMessage.

I thaught i had the anwer by removing my method in: Application.onError() but to no effect. :(
Some other tip for me?

Regards, Jan

try this:

application.output(ex.message);

Same problem here. Servoy 5.2.11

The application.output(ex.message) shows indeed the error message.
But I need to do something depending on the error code.

Is there some ex.property that returns the error code?
Because ex.getErrorCode() is not recognized.

I need it to compare with ServoyException.NO_PARENT_DELETE_WITH_RELATED_RECORDS

There are different kind of exceptions, not all exceptions are ServoyExceptions that do have that getErrorCode()

so for this to work you have to test for that like:

if (ex.getErrorCode && ex.getErrorCode() == ServoyException.NO_PARENT_DELETE_WITH_RELATED_RECORDS) {
 // a servoy exception with that code
}

The exception I get is a servoy exception.

When I don’t use try/catch then the errorhandler is called and the errorcode returns ServoyException.NO_PARENT_DELETE_WITH_RELATED_RECORDS

But when using try/catch this errorcode is not returned.

I had to write my own recursive check if a delete will fail or not before doing the deleteRecord()

that is because if you catch() you don’t get directly a ServoyException
it is a Javascript/Rhino exception that wrappes around the Servoy Java Exception:

application.output(e.javaException.getCause().getErrorCode() == ServoyException.NO_PARENT_DELETE_WITH_RELATED_RECORDS);