zsh-users
 help / color / mirror / code / Atom feed
* Use of { try-list } always { always-list } with "set e-"
@ 2021-07-17 13:03 Zach Riggle
  2021-07-17 20:07 ` Eric Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Zach Riggle @ 2021-07-17 13:03 UTC (permalink / raw)
  To: zsh-users

Hello all!

I'm trying to use the "always" keyword to ensure that some cleanup
happens, even if an error occurs.

Perhaps I'm misunderstanding the intent of this feature, but it seems
that the always-list should be executed, even with "set -e".

===================
set -e
() {
    {
        echo TRY
        false
    } always {
        echo ALWAYS
    }
}
===================

I know that the always-list is executed if there's a "return" or
"exit" statement in the try-list, but I was hoping to be able to put
in some cleanup in the always-list in the event of an error.

Is there any way to achieve what I'm looking to do?

Zach Riggle


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Use of { try-list } always { always-list } with "set e-"
  2021-07-17 13:03 Use of { try-list } always { always-list } with "set e-" Zach Riggle
@ 2021-07-17 20:07 ` Eric Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Cook @ 2021-07-17 20:07 UTC (permalink / raw)
  To: zsh-users

On 7/17/21 9:03 AM, Zach Riggle wrote:
> set -e
> () {
>      {
>          echo TRY
>          false
>      } always {
>          echo ALWAYS
>      }
> }

set -e, as well meaning as the intention was, will always interactive with non posix features in weird ways.
it is pretty much always better to explicitly handle errors that need to abort the entire script instead of
relying on set -e. once you are writing conditional logic, if, while, {} always {}, etc, all bets are off on
how set -e will handle it.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-17 20:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-17 13:03 Use of { try-list } always { always-list } with "set e-" Zach Riggle
2021-07-17 20:07 ` Eric Cook

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).