From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5864 invoked from network); 1 Oct 2005 20:41:38 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 1 Oct 2005 20:41:38 -0000 Received: (qmail 74010 invoked from network); 1 Oct 2005 20:41:32 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 1 Oct 2005 20:41:32 -0000 Received: (qmail 13078 invoked by alias); 1 Oct 2005 20:41:29 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21796 Received: (qmail 13061 invoked from network); 1 Oct 2005 20:41:27 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 1 Oct 2005 20:41:27 -0000 Received: (qmail 73726 invoked from network); 1 Oct 2005 20:41:27 -0000 Received: from ns9.hostinglmi.net (213.194.149.146) by a.mx.sunsite.dk with SMTP; 1 Oct 2005 20:41:27 -0000 Received: from 212.red-80-35-44.staticip.rima-tde.net ([80.35.44.212] helo=localhost) by ns9.hostinglmi.net with esmtpa (Exim 4.52) id 1ELoAl-0003vG-Bx; Sat, 01 Oct 2005 22:41:32 +0200 Date: Sat, 1 Oct 2005 22:41:52 +0200 From: DervishD To: Peter Stephenson Cc: zsh-workers@sunsite.dk Subject: Re: Exception handling and "trap" vs. TRAPNAL() Message-ID: <20051001204152.GB134@DervishD> Mail-Followup-To: Peter Stephenson , zsh-workers@sunsite.dk References: <20050929200741.GA1156@DervishD> <20050930124130.45eb0463.pws@csr.com> <20051001153756.GA12183@DervishD> <1051001183818.ZM27904@candle.brasslantern.com> <20051001191035.2A4F48673@pwstephenson.fsnet.co.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20051001191035.2A4F48673@pwstephenson.fsnet.co.uk> User-Agent: Mutt/1.4.2.1i Organization: DervishD X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - ns9.hostinglmi.net X-AntiAbuse: Original Domain - sunsite.dk X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - dervishd.net X-Source: X-Source-Args: X-Source-Dir: 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.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 Hi Peter :) * Peter Stephenson dixit: > The answer to (2) is this, from the manual regarding function-style traps: > > The return status from the function is handled specially. If it > is zero, the signal is assumed to have been handled, and execu‐ > tion continues normally. Otherwise, the normal effect of the > signal is produced; if this causes execution to terminate, the > status returned to the shell is the status returned from the > function. > > So the whole behaviour that DervishD is seeing is a side affect of the > fact that this: > > TRAPZERR() { throw DEFAULT; } > > finishes by executing a command with non-zero status, the throw, causing > the special behaviour described above. But I didn't see that as a side effect, since the trap is not returning. I assumed that the "throw" broke execution flow, and jumped to the start of the "always" block, that is, no return value from TRAPZERR was involved. I know, the code I was proposing is weird, and ZERR is intended to *handle* errors, not to throwing exceptions, but if inline traps won't cause an "always" block to be run, it should be stated in the manual (IMHO). Probably ZERR is a bad example, but as soon as I started to mess with exceptions and "always" blocks I thought about a trap for SIGINT to do cleanup, using an exception and some "always" blocks. Probably people is not using exception handling in shell script, but if the feature exits, it should work seamlessly with traps or at least document the problem. On the other hand, I don't see any problem in traps not causing exceptions to be thrown, but the behaviour should be consistent and both kinds of traps should behave the same. Otherwise you can write code using function traps and throwing exceptions from the trap, and as soon as you need the trap to be inline (for using $LINENO or any other similar variable) your code will no longer work :( Anyway, thanks a lot for explaining the problem and the decisions behind the behaviour. As I suspected and told to Bart, I wasn't sure this was a bug. Ral Nez de Arenas Coronado -- Linux Registered User 88736 | http://www.dervishd.net http://www.pleyades.net & http://www.gotesdelluna.net It's my PC and I'll cry if I want to...