Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: Henrik Ring on March 05, 2015, 12:03:01 am

Title: Retrieving stacktrace
Post by: Henrik Ring on March 05, 2015, 12:03:01 am
Is there any way to retrieve the stack trace in EA scripts written in JScript/Javascript?

// Somehow retrieve stack trace as string to be logged eg. something like:
try {
  functionThatCausesExceptionWhenCalled();
} catch (e) {
   LOGError(e.message + "\n" + myGetStackTraceAsStringFunction(e) )
}


I can get the stack trace when I debug, but I wish to write the stack trace to the log in case a script fails when running in "none debug" mode.
Title: Re: Retrieving stacktrace
Post by: Wade Brooks on March 06, 2015, 06:35:12 am
you can redirect stdout or stderr to a file.


here is an example of stderr:
script --option parameter    2> error.log

The command shell will start "script"   pass options and parameters to the program.    The "2> error.log" would be removed by the shell and error output would be directed into the error.log file
Title: Re: Retrieving stacktrace
Post by: Henrik Ring on March 16, 2015, 08:57:39 pm
@Wade,
I am running the script from within the context of EA not at at the command line. Could be a script initiated through a right click on an item in the project browser then navigating "Scripts > MyScript".
best regards,
Henrik
Title: Re: Retrieving stacktrace
Post by: qwerty on March 17, 2015, 12:57:06 am
Why don't you print to EA's system console?

q.
Title: Re: Retrieving stacktrace
Post by: Henrik Ring on March 18, 2015, 06:59:52 pm
@qwerty
Yes that will also be helpful. Do you know of a way I can print the stack trace to the system console when not running i debug mode?
Could be something similar to Javas printStackTrace() method.
Title: Re: Retrieving stacktrace
Post by: qwerty on March 18, 2015, 09:11:06 pm
Unfortunately I'm not that familiar with JScript. Probably a method to redirect the stack trace to a string and then send that to EA's console?

q.