Select to view content in your preferred language

Add Error Handling Try Catch to Arcade Language

8309
17
04-14-2021 11:25 AM
Status: Open
Labels (1)
SylvainHotte2
Occasional Contributor

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)
17 Comments
LanceKirby2

One more vote!

PeterKnoop

A try/catch capability would potentially help with the goal of capturing whether the current user has access to a data source, and if not, then return a message in a List widget, rather than popping up the login dialog.

For example, one could wrap FeatureSetByPortalItem with a try/catch to handle the error returned when a user does not have access to a portal item.

DavidStewart3

YES, Please do this.

Here is an Arcade expression code snippet where an error trap would be useful. (This is part of an Arcade expression used to populate an enterprise portal WebMap popup.) As it is, the expression executes fine when one or more features satisfy the filter condition, but fails (ie returns nothing) when no features are found:

var returnText = "ipsum dolorum";

var allFeatures = FeatureSetByPortalItem(port, mapID, layerID);

var where = 'CNTRCT_ID=<some value>';

var foundFeatures = Filter(allFeatures, where); // code fails at this point

if (foundFeatures == null)

returnText = "No features found";

else

returnText = Count(foundFeatures) + " features were found";

return returnText;

jrosacker

Interestingly, Esri has reserved some relevant keywords in Arcade:

jrosacker_1-1747167085892.png

Hopefully this idea gets approved!

HuajunChenGarland

Yes, please.

It is how I want to use it.

function ToDateSafe(val) {
    var d = null;
    try {
        d = Date(val);
    }
    catch(err) {
        d = null;
    }
    return d;
}
JBH
by

Yes, need!

RobinKurosawa

+1 to this thread.

Without a way to explicitly handle failures, engineers are forced to rely on defensive patterns and implicit failure behavior. This makes logic harder to test, harder to audit, and harder to build on top of, and harder to fix — especially when expressions cannot be easily executed or tested outside the platform.