Feature Request: Try/Catch/Finally

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.

5 Likes

3 posts were split to a new topic: Need Better Execute Script Error Handling

You got my vote.! :thumbsup:

Noted.

3 Likes

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?

2 Likes

This would be a really very useful action to have in the toolkit.

2 Likes

It remains on the Todo list.

2 Likes

’Twould be nice.

Anything that really improves debugging macros would be helpful.

It would be really helpful if the failure mechanism could include the UUID of the failed action as part of its output.

That would make it possible for Peter (or the user) to create a mechanism for going to the failed action in the Keyboard Maestro Editor.

-Chris

4 Likes

@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.

Just my thoughts.

7 Likes

Try/Catch and Throw actions are done for the next major version.

There is no Finally section, since they can simply be put after the action.

6 Likes

That's awesome! Thanks so much!

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!!! :heart:

1 Like

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.

1 Like

Is "external cancel" over-rideable and thus reportable?

As in "the macro really must make further progress before it can safely stop"?

No.

No.

There is no way to guarantee that. There never is, since Keyboard Maestro Engine could be quit, or Mac could shutdown.

1 Like