I have a question of style, and I know this might require a lengthy reply. So please bear with me and thanks ahead of time if you take time to reply.
I have (several) big scripts that do a lot of different functions, many of them involve making PDFs from InDesign and copying them to various places. I need to have a way to know if there’s been an error in some step and be able to cancel out/stop/escape out of the main function, but also be able to do something when it errors out. Several of my steps are function calls, but some things are just steps in order to be done in the main function, too small to break out (I feel). How do I register if there has been an error in any sub function and then drop out of the main function? Is it just a matter of nesting many levels of Try/On Error? I have one script that checks about 9 times if a variable “myContinue” is True, and script continues if it is true, or skips to the end if it is false. But this requires placing that “if myContinue is true…” statement all over the place. Plus if there is an error inside of the function I still need to be able to bail out and register that too.
I guess I’m looking for a more simplified way to detect this kind of situation. Would there be something similar to “do while…” statement that scans the trueness at every single step of the function?
Here’s what I have devised now:
global myContinue
on clicked theObject
set myContinue to true
if myContinue is true then
--do some stuff
--set some global variables
end if
if myContinue is true then
tell app "InDesign"
--do some stuff
end tell
end if
if myContinue is true then
doAFunction()
end if
if myContinue is true then
doSomeOtherFunction()
--do some stuff
doMoreFunction()
end if
if myContinue is false then
--do some error messages or clean up routines
end
end clicked
on doAFunction()
--do some things
--set some global variables
--return myContinue as True or False
end doAFunction
Does anyone have any suggestions to streamline this sort of code some more?