From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10161 invoked from network); 3 Oct 2005 08:57:51 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 3 Oct 2005 08:57:51 -0000 Received: (qmail 38655 invoked from network); 3 Oct 2005 08:57:45 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Oct 2005 08:57:44 -0000 Received: (qmail 7787 invoked by alias); 3 Oct 2005 08:57:41 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21807 Received: (qmail 7777 invoked from network); 3 Oct 2005 08:57:41 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 3 Oct 2005 08:57:41 -0000 Received: (qmail 38288 invoked from network); 3 Oct 2005 08:57:41 -0000 Received: from cluster-c.mailcontrol.com (HELO rly10c.srv.mailcontrol.com) (168.143.177.190) by a.mx.sunsite.dk with SMTP; 3 Oct 2005 08:57:39 -0000 Received: from exchange03.csr.com (mailhost1.csr.com [81.105.217.43]) by rly10c.srv.mailcontrol.com (MailControl) with ESMTP id j938vXKf015596 for ; Mon, 3 Oct 2005 09:57:35 +0100 Received: from news01 ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Mon, 3 Oct 2005 09:59:30 +0100 Date: Mon, 3 Oct 2005 09:57:38 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: Exception handling and "trap" vs. TRAPNAL() Message-Id: <20051003095738.3de5a059.pws@csr.com> In-Reply-To: <1051003013758.ZM3107@candle.brasslantern.com> References: <20050929200741.GA1156@DervishD> <20050930124130.45eb0463.pws@csr.com> <20051001153756.GA12183@DervishD> <1051001183818.ZM27904@candle.brasslantern.com> <20051001202856.GA134@DervishD> <1051002044052.ZM28373@candle.brasslantern.com> <20051002190940.437F9866F@pwstephenson.fsnet.co.uk> <1051002195518.ZM2163@candle.brasslantern.com> <20051002230027.GA194@DervishD> <1051003013758.ZM3107@candle.brasslantern.com> Organization: Cambridge Silicon Radio X-Mailer: Sylpheed version 0.9.12 (GTK+ 1.2.10; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 03 Oct 2005 08:59:30.0065 (UTC) FILETIME=[C3CBB010:01C5C7F8] X-Scanned-By: MailControl A-05-40-00 (www.mailcontrol.com) on 10.67.0.120 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 Bart Schaefer wrote: > In zsh prior to 4.1.something, an error condition in an inline trap > *WAS* passed through to the calling context. That it now is not, is > apparently either a broken behavior or an undocumented change, and in > any case no code written for older zsh could have relied upon errors > in traps being inconsequential. I think this is 19575: reading the "-" path in the diff the old behaviour of setting trapret if errflag is set was there, and a subsequent "errflag = =3D 1" depended solely on that, not being in a function. Given the description it doesn't look like the change was intentional, even though arguably it should be the way it now is. > [ASIDE: The bash2 behavior implies that traps set globally outside > of a function are not supposed to apply within the function context. > 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 > so that it is tripped if/when the function itself returns nonzero. > This is, almost, the inverse of zsh's "setopt localtraps" behavior.] This is presumably implementable without too much horror, since we can already save and restore traps. It would probably now need to be an option, though. > Ra=FAl ... the important point that you're missing is that zsh doesn't > really have or handle exceptions. Peter's throw/catch functions are > simulations of exception behavior using a mechanism that is far less > powerful than true exception handling. Yes, it's all just based on testing a single variable and relying on the fact that zsh has to unwind the state during an error anyway. Maybe the zshcontrib entry needs more cautionary wording. > 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. eval { ... } would mean that "eval" could no longer be a true builtin but would have to be treated as a reserved word early in parsing. We can second-guess the later stages in processing (is eval disabled?), so probably it can be done without major grief, but the zsh syntax isn't really comparable to Perl. > (In fact, a very useful extension would > be to add an EVAL_ERROR variable that is 1 if an "eval" stopped with > an error, and 0 if "eval" finished normally, so that an error could be > distinguished from "eval false".) This, presumably, is simple. > Presently (that is, without either of my patches), a TRAPNAL function > handles error conditions like a function call, whereas an inline trap > handles error conditions like an "eval" statement. That's defensible, > in a way, because a "trap" command *looks* like an "eval" statement; > it contains a string that is evaluated as commands. It could even be > explained that way in the docs, so that you would have understood why > your sample script didn't work. Yes, this all sounds rational. > 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. --=20 Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 This message has been scanned for viruses by BlackSpider MailControl - www.= blackspider.com