From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23268 invoked from network); 1 Oct 2005 18:38:35 -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 18:38:35 -0000 Received: (qmail 1101 invoked from network); 1 Oct 2005 18:38:29 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 1 Oct 2005 18:38:29 -0000 Received: (qmail 22170 invoked by alias); 1 Oct 2005 18:38:25 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21793 Received: (qmail 22161 invoked from network); 1 Oct 2005 18:38:24 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 1 Oct 2005 18:38:24 -0000 Received: (qmail 773 invoked from network); 1 Oct 2005 18:38:24 -0000 Received: from vms044pub.verizon.net (206.46.252.44) by a.mx.sunsite.dk with SMTP; 1 Oct 2005 18:38:23 -0000 Received: from candle.brasslantern.com ([71.116.81.225]) by vms044.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0INP00LGV2FX3450@vms044.mailsrvcs.net> for zsh-workers@sunsite.dk; Sat, 01 Oct 2005 13:38:22 -0500 (CDT) Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id j91IcKOm027906; Sat, 01 Oct 2005 11:38:20 -0700 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j91IcJhw027905; Sat, 01 Oct 2005 11:38:19 -0700 Date: Sat, 01 Oct 2005 18:38:18 +0000 From: Bart Schaefer Subject: Re: Exception handling and "trap" vs. TRAPNAL() In-reply-to: <20051001153756.GA12183@DervishD> To: Peter Stephenson Cc: DervishD , zsh-workers@sunsite.dk Message-id: <1051001183818.ZM27904@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii References: <20050929200741.GA1156@DervishD> <20050930124130.45eb0463.pws@csr.com> <20051001153756.GA12183@DervishD> Comments: In reply to DervishD "Re: Exception handling and "trap" vs. TRAPNAL()" (Oct 1, 5:37pm) 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 On Oct 1, 5:37pm, DervishD wrote: } Subject: Re: Exception handling and "trap" vs. TRAPNAL() } } Hi Peter :) } * Peter Stephenson dixit: } > Add some "print"s to the trap to see when it's triggering. } } The trap is triggering just in the "false" statement, and the } TRAPZERR works perfectly, it's the "trap" kind which is failing. I ran this with "set -x" (much better than inserting print statements) and it's clear that the "trap" command version of the trap is not tripping the "always" block: +./script:34> false +./script:34> throw DEFAULT +throw:34> typeset -g 'EXCEPTION=DEFAULT' +throw:34> readonly 'THROW=0' +throw:34> (( TRY_BLOCK_ERROR == 0 )) throw:34: read-only variable: THROW +throw:34> THROW='' +./script:35> throw EXCEPTION The problem is this snippet in signals.c: } else if (errflag) trapret = 1; execrestore(); lexrestore(); if (trapret > 0) { if (isfunc) { breaks = loops; errflag = 1; } else { lastval = trapret-1; } We start that section with errflag == 1 and set trapret = 1, but then at lexrestore(), errflag is reset to zero, and because isfunc is false, it's not set back to 1 again. After unwinding out of the trap handler, execution of the try block finds errflag == 0, and proceeds rather than skipping ahead to the always block. So the question is: Why ignore errors that occur in inline traps? } Can I do anything to make it work (except patching zsh)? I don't think so. } Is there any other way of throwing exceptions automagically when a } command returns a non-zero status No.