Add Error Handling Try Catch to Arcade Language

762
3
04-14-2021 11:25 AM
Status: Open
Labels (1)
SylvainHotte2
New Contributor II

Like any language Arcade should have error handling functionality. 

It would be help full to have a Try Catch and be able to get the error description

try {

...code

}

catch (err){

...code

}

 

Tags (2)
3 Comments
jcarlson

This is a great idea, I would use this all the time.

RichardJShepherd

Thanks for raising the idea, @SylvainHotte2 @jcarlson . We've discussed various plans for adding more error management within Arcade.

We'd be interested in what scenarios you have in mind? For instance:

- catching when something has gone wrong within a library function?

- your own script logic throwing exceptions to be caught in an outer scope of the script?

- being able send your own error/exception information out of the script for the application to receive/log/act on?

 

SylvainHotte2

Currently I use Arcade in attribute rules. I use the a lot the {"errorMessage":"a message to the user"} to send back error to the user telling them what is the cause of the error.

However, a try catch would be helpful to capture runtime error and send a more descriptive message. Here an Example. In that code sample we validate (Constraint Rule) the the new value the user entered really exist in an other table (we validate the relationship). I edit the code to simplify the example.

SylvainHotte2_1-1618500926891.png

In this example, If the Filter returns nothing then First return Null. To prevent a runtime error I need to check for null before getting the .STATUS_CODE attribute. Depending on code there could be many of those kind of check. Also, it might be something wrong with a library, or something we did not think of. I would rewrite like this

SylvainHotte2_2-1618501337406.png

In other scenario I written function in my arcade script (ex: recursive, reuse code, etc) I might also be interesting to be able to throw Exception instead of outputting and array like having the first element a Boolean for success or Fail, and the second for the data. 

As for sending My own Exception outside I recently see that now the full attribute rule error message we see in pro is not sent to the .Net SDK. That is good. If you could go a step further and being able to the the detail in an object (Rule Name, Error Code, Error Description, etc ) but I guess I can deserialize the Json my self. I also notice the tools like FME does not report error correctly when the is an attribute rule constraint. The is just an generic error message the the message part is just {}. 

While I have your attention, I know we are not Christmas yet, but I will be fun to be able to build our own Arcade Function Library  and Import them in the Arcade Script. Let say I create a advance TitleCase function, or other generic function that I use in many other script, Instead of copy paste the function, I could just create a library and import it. I could event share those libraries to others.

Hope it give a more detail idea of what I had in mind

Regards

Sylvain