With some recent posts talking about tracking down errors, and how to handle them, I thought I'd revisit this request with some more detail. (At least, I think I requested this before.)
I'd love to see a Try/Catch/Finally mechanism put in place. From the perspective of the editor, it could look something like this:
Logic-wise, if an action has "Failure aborts macro", that would be considered the error that "Catch" would catch. I suppose this might mean renaming "Failure aborts macro" to "Failure generates error", or something like that, but it wouldn't have to.
I'm not sure about "Notify on Failure". My first thought is that it would NOT notify if it's caught, but the wording might be confusing.
And finally (pun intended), I suppose this probably means we'd also need a "Throw" action, which I suspect is the easiest part of this request.
I realize this is not a simple request. But I think it's fairly obvious how useful it could be.
Thanks. Add this to the feature requests for v8. It would make a great addition, and although I would obviously upgrade regardless, it could be a pretty compelling reason to upgrade.
Again, a great idea, Dan. This would be very useful to lots of KM users.
Currently, I think a lot of KM users are confused and mystified when their macro fails with very little helpful info.
@peternlewis, I see that you "noted" this back in 2017.
Have you given this any further thought?
@peternlewis I think Chris has made an incredible point. One of the biggest time sinks in working with macros is finding out where something went wrong. And for new users, it can be a deal-breaker.
Even if you don't implement try/catch/finally, if error messages could somehow point you to the action that caused the problem, it would be incredibly useful. I know actions don't have UUIDs, and personally, I'd rather see line numbers (action numbers? step numbers?) that are displayed in the editor.
I'm thrilled to get the try/catch and throw! I hope they handle normal action "errors" too, like regex failing, Find Image failing, etc.
Regarding no Finally section, the main reason I want it is so I can guarantee that some set of actions gets executed even if the macro gets exited intentionally via one of the Cancel Macro actions, or aborted due to a prompt being canceled - that sort of thing which probably isn't handled by a "catch".
But I'm not complaining! Getting the try/catch is awesome, for sure!!!
For any action within the Try section that fails and would abort the macro, aborts the Try part and executes the Catch part, setting the ActionResult token to the error. Any notification that failure would provide is disabled. The Catch section then runs as normal (if there are no failures, then it does not run at all). A a prompt is aborted, that would be caught.
If the macro is canceled externally (eg from the Cancel menu, or a Cancel All Macros), then the macro is still canceled.