cancel
Showing results for 
Search instead for 
Did you mean: 

SAC; Story; tryStatement

attila_kiss
Explorer

Is it possible to write TRY-CATCH-FINALLY statement in script in order to provide a 'friendlier' error message for the users?

Many thanks in advance!

Accepted Solutions (0)

Answers (1)

Answers (1)

Pascal_D
Advisor
Advisor

Hi,

this is currently not possible. I use a workaround with the if() clause.

For example I have a variable which is a selection from a Table:

var selection = Table_1.getSelections()[0];

Normally, the function getSelections() returns of Type Selection. However, if the user clicks on the dimension title instead of a dimension member, the function getSelections() would return unassigned which could later lead to a TypeError, if the variable is later used.

To avoid an error message being shown or to show an alternative Error, you can use an if() clause for the code snippet using this variable:

if(selection) {
YOUR CODE
}

 For an alternative Error-Message you can use the else statement:

else {
Application.showMessage(ApplicationMessageType.Error,"Your Text");
}

 This method should also work for other use cases beside the TypeError.

Hope this helps.