How to bail out of a nested function?
Copy link to clipboard
Copied
Dear all,
In the good old days of 'large computers' I had an Exit routine which allowed me to terminate a Fortran program and return to the OS without the need to maintain a return chain to the top of the program structure.
I'm really missing such a thing in ESTK (or elsewhere in JS). Condition in this script can be entered only if the script has been started in ESTK - not via the menu in FM (menu appears only if document is active). So the situation may not be that dramatically - because a person doing so must be at least (as I am) somewhat familiar with ESTK and know how to proceed. Nevertheless I'm looking out for principle escape function.
Throwing an error
function IniFMGraph () {
var oDoc = app.ActiveDoc;
if (!oDoc.ObjectValid()) { // may be just the Welcome screen, but no FM document
alert ("IniFMGraph\nNo active document!\nCan not place a diagram.", "FMgraph [DDD]", false);
throw new Error ("Script stopped");
}
}
opens ESTK at that place and uses the status line for a message.
Is there a 'catch' method for the upper-most function (main) - or even a method to leave the script without further cluttering the screen?
I do not have a deep enough knowledge of event handlers...
Any ideas?
Have something to add?

