Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zmv exits from function




On 2024-01-02 09:47, Mark J. Reed wrote:


Thanks.  Man, I wish there were more examples :(


Well, no.  It runs the code on the left, and then when it finishes it runs the code on the right. That's the extent of the `always` functionality. What makes it special is that the code on the right runs even if the code on the left blows up somehow.
Yeah, I think I get it.  But the 'memo' has to be there -- zmv must ... or maybe not ... when zmv returns, if the 'always' keyword (sorta) it there, then it knows to not crash but to execute the following code.  So, yeah, it could be seen as 'linear'. 

It's similar to a feature called the "finally block" in other languages, where it's usually attached to the exception-handling mechanism; something like `try { start here } catch (ErrorType) { do this if the previous block failed this particular way } finally { run this no matter what }`.  Because of that similarity, the code on the left of the `always` is called the "try block" or "try list", even though zsh doesn't use the keyword "try". The code on the right is called the "always block" or "always list".
That's interesting.  So this isn't some desperate hack -- that kind of functionality is standard to some degree.  Ok, good to know. But as I said, it sure looks strange the first time you see it.  Reading a bit more, I see it's got other uses than preventing meltdowns.  Cool.

If you want the world not to be blown up, you can set TRY_BLOCK_ERROR to 0, and then zsh will forget that anything went wrong and continue about its business.

I myself hardly ever want Ragnarok, so next time I run into this sort of issue, I've got that to defuse it.  Thanks Mark.  Hey, I wonder if that could be an option? NO_MELTDOWNS=on




Messages sorted by: Reverse Date, Date, Thread, Author