Can I set "execute this macro x if there is any critical abort failure"?

I have a Macro group which contains several macros being executed one after the other in a cycle.

If a failure occurs (like image not found), then the whole job is aborted, and everything stops.

I want to be able to set “if there is a critical failure abort then execute this macro x

The macro x will be a macro in the macro group and it will reset the screen and browser and start the cycle again.

Is that possible?

This is what the "Try/Catch" Action is for -- try to do something, if it fails then do something else.

How you use it will depend on how your macros are structured and what you want to achieve. You could try and detect each image, special-casing each error (reload the web page until the image appears for one, set a default result for another, and so on). You could "Try" each sub macro in turn, repeating each until it succeeds and resetting to the point before the failing sun macro should execute. Or you could wrap all your subs in a single "Try", resetting to an initial state if any of them fail, and repeating the chain again and again until they all succeed:

So lots of options (and I'm sure others can come up with more!).

Here's the "Error Demo" Group containing the "main" macro above plus the two sub macros:
Error Demo Macros.kmmacros (7.3 KB)

When you run "main" you'll have 5 seconds to put a value into prompt "Sub 1" -- if you don't, the loop restarts. If you do it goes on to prompt "Sub 2" -- if you don't enter a value there within 5 seconds it'll loop back to prompt "Sub 1" again.

Pay close attention to how the options are set on both the "Execute Macro" Actions in "main" and the "Prompt" Actions in the sub. You want errors in the subs to abort the macro -- "Try/Catch" needs to receive them. But you'll probably want to turn most, if not all, error notifications off.

Have a play, try splitting it into two blocks so it resets to the beginning when "sub1" fails but only repeats "sub2" if "sub1" succeeds. And ask if you've any questions!

2 Likes

what about this, just after every image-find ? (I turned off abort on failure on the image find)

You can but, as you say, you'll have to add that after each and every possible failure and turn the "Abort..."s on the immediately preceding Actions. You can't "try this set of Actions as a group and if any one of them fails...".

And remember that the macro calling macro "7..." as the result of an error will not itself complete until macro "7..." does, unless you are setting that "Execute a Macro" Action to run asynchronously.

That is a slight worry about your initial description of

If 1 executes 2 synchronously (the default), then 2 executes 3, etc then all 6 macros are executing simultaneously near the end. If those "Executes" are within "If" or "Group" Actions then that could add up to 15+ "executing instances" (more if more deeply nested) towards your default maximum of 50 concurrently-executing instances. That's why it's more common to have a "controller" that fires off sub macros one at a time in sequence rather than chaining the macros together, one calling another calling another.