Subscribe Bookmark RSS Feed

Show the Line of an Error with Throw()

senatorx

Community Trekker

Joined:

Jun 12, 2012

Hey,

I'm trying to handle some unavoidable errors with Try and Throw.  Looking at Throw in the Index it says:

Throw("text")

Function

Returns a Throw. If you include text, throwing stores text in a global exception_msg. If text begins with "!", throwing creates an error message about where the exception was caught.

So I tried this to get the error line:

try(abcdef;

      ,

      throw("!nice error.");

);

show(exception_msg);

This doesn't seem to work as intended, since it doesn't show the line that created the error or give a line number.  It sounds like the info is stored in exception_msg, but script execution halts after the throw, so I cannot display it.

Has anyone had success with getting the line that caused the error?

1 REPLY
senatorx

Community Trekker

Joined:

Jun 12, 2012

I believe I've figured it out - the Throw has to be contained within a function so that script execution will continue outside of the function:

doMath = Function({a,b,c}, {Default Local},

      ::result = a*b*c;

           Try(

                 abcde;

                 ,

                 Throw("!nice error.");

           );

);

show(result);

show(exception_msg);

and I get from the log:

exception_msg = {"Name Unresolved: abcdef"(1, "abcdef", abcdef)};

Is there any way to get an actual Line Number?  It could get quite messy trying to find where that line is located!