Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Exception handling and "trap" vs. TRAPNAL()
- X-seq: zsh-workers 21811
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: Exception handling and "trap" vs. TRAPNAL()
- Date: Mon, 03 Oct 2005 14:51:41 +0000
- In-reply-to: <20051003095738.3de5a059.pws@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20050929200741.GA1156@DervishD> <20050930124130.45eb0463.pws@xxxxxxx> <20051001153756.GA12183@DervishD> <1051001183818.ZM27904@xxxxxxxxxxxxxxxxxxxxxxx> <20051001202856.GA134@DervishD> <1051002044052.ZM28373@xxxxxxxxxxxxxxxxxxxxxxx> <20051002190940.437F9866F@xxxxxxxxxxxxxxxxxxxxxxxx> <1051002195518.ZM2163@xxxxxxxxxxxxxxxxxxxxxxx> <20051002230027.GA194@DervishD> <1051003013758.ZM3107@xxxxxxxxxxxxxxxxxxxxxxx> <20051003095738.3de5a059.pws@xxxxxxx>
On Oct 3, 9:57am, Peter Stephenson wrote:
} Subject: Re: Exception handling and "trap" vs. TRAPNAL()
}
} Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > In zsh prior to 4.1.something, an error condition in an inline trap
} > *WAS* passed through to the calling context.
}
} it doesn't look like the change was intentional, even though arguably it
} should be the way it now is.
It could also be argued that, if the trap should behave like an "eval",
it ought to set $? = 1 when an error occurs inside the trap (but still
not cause an interrupt condition). The example of bash2 contradicts
that position. Can anyone who is reading this try ksh?
} > E.g., in bash2 a global INT trap does not prevent the function from
} > being interrupted by a SIGINT; instead it handles the signal in the
} > context where the trap command was run. Similarly an ERR trap stops
} > being tripped during the body of the function, but remains in effect
}
} This is presumably implementable without too much horror, since we
} can already save and restore traps.
It's worse than just saving and restoring traps. It requires treating a
function call like a subshell, in that both the function and the caller
get the SIGINT, the function is interrupted, and the caller's trap is
trigged.
} It would probably now need to be an option, though.
Yes.
} > The zsh "always" syntax could -- and perhaps even should -- have been
} > implemented equally well as a new syntax for the "eval" builtin, much
} > like Perl's "eval" can be followed by a curly-bracketed block instead
} > of a string.
}
} That's not particularly natural in zsh.
I didn't really mean that the syntax would be exactly like Perl's, just
that the behavior would be. If you wanted to implement something as
close as possible to "always" in an older version of zsh, you'd do
something like:
eval "print this is the try block"
TRY_ERR=$?
print "this is the always block"
if (( TRY_ERR == 0 ))
then
print "this is what comes after the always block"
else
# This is a stupid way to reset $? without exiting from the
# parent shell script when we aren't in a function body.
( return TRY_ERR )
fi
} > Given all of this plus the bash2 behavior, I'm inclined to add a few
} > more words to the documentation and apply *neither* of the patches
} > from workers/21804. Further, *IF* we were going to choose one of
} > those patches to apply, I'd say it should be the first one, to make
} > TRAPNAL ignore errors too.
}
} It looks like the reason for the error to be propagated is receding into
} history and I'd be perfectly happy with that patch.
As I said, I'm actually leaning towards no patch at all. However, the
reason for propagating the error isn't actually receding, because Raúl
says he needs that behavior, and given "always" it really is useful.
Here's a possible compromise: Use my second patch, but propagate the
error if and only if we're in the try-block of an always-construct.
That's guaranteed not to break old code, and continues to behave like
bash2 in the absence of "always". Can dotrapargs() determine that it
is in "always" context without too much trouble?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author