I’d like to know: is there anyway that I could end or exit the function call when throwing exception like scenario below.
script A.
function A1
try
run command 1
run command 2
run command 3
run command 4
catch
LogError “…”
end try
end function.
script B
try
[“scriptA” A1]
some other function called here.
catch
LogError
end try
For example, the script execute run command 2 and got error. Is there any function that I can put in the catch block so that it could end the [“scriptA” A1], function instead of continue execute run comand 3 and 4, then execute the next function call from script B.
You almost answered your own question. The command that you’re looking for is “exit”. You specify a parameter telling it what to exit, as shown here:
exit handler // exits the current handler
//can also be executed as "exit on" or "exit function" as appropriate
exit [handlername] // same as exit handler
exit all // ends all script execution
exit repeat // ends a repeat loop and jumps to the next line of the script following the "end repeat"
I have main script which executes/calls the action script dynamically.I also have subscript which are called by these action scripts to perform specific task.
The requirement is whenever a sub script fails it has to move on to the next action script.
Currently i use exit script or exit handler which exits only the sub script and not the action script.
I tried exit handlername like exit ActionScript but the sysntax seems to be wrong.
It will be helpful if you could provide a solution on the same.
I think instead of using exit in the subscripts, you’re going to have to have them return a value that you can examine and then exit the “action” script based on that return value. Putting a “return” statement in the script will immediately return control to the calling script, so it’s effectively the same as calling “exit” in the subscript.
I understand but if i do that way i will have to touch a lot of scripts.
So i am looking out for a solution like exiting directly from single subscript rather then touching all action scripts
Another approach that you might try would be to throw an exception in the subscript rather than trying to exit or return a value. Then you can use try/catch to catch the exception in the main script without having to change your action scripts.