From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4452 invoked from network); 28 Sep 2005 15:20:23 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 28 Sep 2005 15:20:23 -0000 Received: (qmail 78603 invoked from network); 28 Sep 2005 15:20:18 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 28 Sep 2005 15:20:18 -0000 Received: (qmail 16363 invoked by alias); 28 Sep 2005 15:20:16 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21779 Received: (qmail 16354 invoked from network); 28 Sep 2005 15:20:15 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 28 Sep 2005 15:20:15 -0000 Received: (qmail 78326 invoked from network); 28 Sep 2005 15:20:15 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 28 Sep 2005 15:20:15 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Wed, 28 Sep 2005 16:17:50 +0100 Received: from news01 ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC (5.0.2195.6713); Wed, 28 Sep 2005 16:21:26 +0100 Date: Wed, 28 Sep 2005 16:19:29 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: About zsh-users 8489 (exception handling) Message-Id: <20050928161929.726e31e6.pws@csr.com> In-Reply-To: <1050928024249.ZM23758@candle.brasslantern.com> References: <20050927234726.GC988@DervishD> <1050928024249.ZM23758@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="us-ascii" Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 28 Sep 2005 15:21:26.0642 (UTC) FILETIME=[4B131520:01C5C440] 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: > I think EXCEPTION should also be declared with "typeset -g", so that > makes the complete function look like: > > throw() { > typeset -g EXCEPTION="$1" > readonly THROW > if (( TRY_BLOCK_ERROR == 0 )); then > # We are throwing an exception from the middle of an always-block. > # We can do this by restoring the error status from the try-block. > # (I am not convinced I ever intended this to work, but it does...) > (( TRY_BLOCK_ERROR = 1 )) > fi > # Raise an error, but don't show an error message. > # This is a bit of a hack. (Surprised?) > THROW= 2>/dev/null > } How about this... Index: Doc/Zsh/contrib.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/contrib.yo,v retrieving revision 1.47 diff -u -r1.47 contrib.yo --- Doc/Zsh/contrib.yo 22 Sep 2005 22:23:45 -0000 1.47 +++ Doc/Zsh/contrib.yo 28 Sep 2005 15:16:36 -0000 @@ -1284,8 +1284,8 @@ In common with exception handling in other languages, the exception may be thrown by code deeply nested inside the `try' block. However, note that it must be thrown inside the current shell, not in a subshell forked for a -pipline, parenthesised current-shell construct, or some form of -substitution. +pipeline, parenthesised current-shell construct, or some form of +command or process substitution. The system internally uses the shell variable tt(EXCEPTION) to record the name of the exception between throwing and catching. One drawback of this Index: Functions/Exceptions/throw =================================================================== RCS file: /cvsroot/zsh/zsh/Functions/Exceptions/throw,v retrieving revision 1.1 diff -u -r1.1 throw --- Functions/Exceptions/throw 15 Feb 2005 18:32:38 -0000 1.1 +++ Functions/Exceptions/throw 28 Sep 2005 15:16:36 -0000 @@ -19,11 +19,12 @@ # script. # The following must not be local. -EXCEPTION="$1" +typeset -g EXCEPTION="$1" +readonly THROW if (( TRY_BLOCK_ERROR == 0 )); then # We are throwing an exception from the middle of an always-block. # We can do this by restoring the error status from the try-block. (( TRY_BLOCK_ERROR = 1 )) fi # Raise an error, but don't show an error message. -{ ${:?THROW} } 2>/dev/null +THROW= 2>/dev/null -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************