From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14644 invoked from network); 1 Oct 2005 12:41:51 -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 12:41:51 -0000 Received: (qmail 62421 invoked from network); 1 Oct 2005 12:41:44 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 1 Oct 2005 12:41:44 -0000 Received: (qmail 20730 invoked by alias); 1 Oct 2005 12:41:36 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9463 Received: (qmail 29443 invoked from network); 30 Sep 2005 11:41:36 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 30 Sep 2005 11:41:36 -0000 Received: (qmail 14050 invoked from network); 30 Sep 2005 11:41:36 -0000 Received: from cluster-c.mailcontrol.com (HELO rly07c.srv.mailcontrol.com) (168.143.177.190) by a.mx.sunsite.dk with SMTP; 30 Sep 2005 11:41:35 -0000 Received: from exchange03.csr.com (mailhost1.csr.com [81.105.217.43]) by rly07c.srv.mailcontrol.com (MailControl) with ESMTP id j8UBfWU8012460 for ; Fri, 30 Sep 2005 12:41:32 +0100 Received: from news01 ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Fri, 30 Sep 2005 12:43:25 +0100 Date: Fri, 30 Sep 2005 12:41:30 +0100 From: Peter Stephenson To: zsh-users@sunsite.dk Subject: Re: Exception handling and "trap" vs. TRAPNAL() Message-Id: <20050930124130.45eb0463.pws@csr.com> In-Reply-To: <20050929200741.GA1156@DervishD> References: <20050929200741.GA1156@DervishD> 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=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 30 Sep 2005 11:43:25.0965 (UTC) FILETIME=[2B35ABD0:01C5C5B4] X-Scanned-By: MailControl A-05-40-00 (www.mailcontrol.com) on 10.67.0.117 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 DervishD wrote: > --- cut here --- > #!/bin/zsh > > emulate -L zsh > > [[ "$1" = "trap" ]] && trap 'throw DEFAULT' ZERR > [[ "$1" = "TRAPZERR" ]] && function TRAPZERR() { throw DEFAULT ; } > > { > print "Before throwing" > # This should throw "DEFAULT" exception > false > throw EXCEPTION > # This shouldn't be shown > print "After throwing" > } always { > catch * && print "Caught exception $CAUGHT" > return 0 > } > > --- cut here --- > $ ./script trap > Before throwing > Caught exception EXCEPTION > > I'm puzzled. The "trap" trap is executed in the current > environment, so I assume it would throw "DEFAULT", as intended, as > soon as we hit the "false". It doesn't and I don't know why. OTOH, > the TRAPZERR function, which runs "throw" in its own environment, > works ok :??? WHY? Add some "print"s to the trap to see when it's triggering. You may find it's throwing additional exceptions at points you don't want it to which is gumming things up. Mixing traps with the exception functions in this ways is bound to be hairy and I'd suggest you avoid doing it. -- 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