Try Catch Suggestion

Hi, this is more a suggestion than a problem. Also, as you read this bear in mind that I am still using ver 3.9.7 and am 5 versions of wappler behind, so if this is already done in later versions, good. Also, maybe I am being a bit clumsy in my constructs so suggestions in my technique are welcome.

The suggestion is to make the code a lot easier in the server side action steps. Here is an example of what I am doing, which is to put a Try/Catch around every step that executes something external to wappler, in this case, a FileUpload and a Database Insert. I find that if I do not do this and there is an error then the Step just stops with no error message.

image

Its always the same with the Error being a response of $_Error (for me anyway).
I was just wondering if the $_Error could be automatically generated in such steps, without the need for a try catch. And I do realise that means that a customization of the error message from just being $_Error would be foregone but that can be done in the onError in the App anyway.
If this was adopted then my code would look like …
image
How simple is that! And much more maintainable.

Don’t quote get your point here.
Try catch is there so that you can handle the error on server side itself.
If you don’t want that, just don’t use it and wherever the error occurs, SA returns the $_ERROR to client. SA will stop execution at the step where error has occurred.

Ok, i did not know that $_Error gets returned if you do not use try/catch. I presume that it gets returned in lasterror.response, which would be completely fine.
I will try it out, thanks.

Hi Sid, just a follow up on our conversation. Things did not work out as expected.

In my first example using Try/Catch I get a clear message of a problem in Error Dynamic Event when it occurs. The second example that does NOT use Try/Catch displays an empty response in the Error Dynamic Event. Do you know how to fix that?

If second example did display a proper lasterror.response than that would satisfy my original suggestion.

What do you see in the last error response when you don’t use try/catch?
It should return the same thing that you see in $_ERROR. Try checking in browser console as well via dmx.app.data...
Do you have the DEBUG option enabled in Server Action settings?