zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Peter Stephenson <pws@csr.com>
Cc: DervishD <zsh@dervishd.net>, zsh-workers@sunsite.dk
Subject: Re: Exception handling and "trap" vs. TRAPNAL()
Date: Sat, 01 Oct 2005 18:38:18 +0000	[thread overview]
Message-ID: <1051001183818.ZM27904@candle.brasslantern.com> (raw)
In-Reply-To: <20051001153756.GA12183@DervishD>

On Oct 1,  5:37pm, DervishD wrote:
} Subject: Re: Exception handling and "trap" vs. TRAPNAL()
}
}     Hi Peter :)
}  * Peter Stephenson <pws@csr.com> 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.


       reply	other threads:[~2005-10-01 18:38 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20050929200741.GA1156@DervishD>
     [not found] ` <20050930124130.45eb0463.pws@csr.com>
     [not found]   ` <20051001153756.GA12183@DervishD>
2005-10-01 18:38     ` Bart Schaefer [this message]
2005-10-01 19:10       ` Peter Stephenson
2005-10-01 20:41         ` DervishD
2005-10-01 22:44         ` Bart Schaefer
2005-10-02  8:06           ` DervishD
2005-10-01 20:28       ` DervishD
2005-10-02  4:40         ` Bart Schaefer
2005-10-02  8:13           ` DervishD
2005-10-02 19:09           ` Peter Stephenson
2005-10-02 19:55             ` Bart Schaefer
2005-10-02 23:00               ` DervishD
2005-10-03  1:37                 ` Bart Schaefer
2005-10-03  8:57                   ` Peter Stephenson
2005-10-03 14:51                     ` Bart Schaefer
2005-10-03 15:10                       ` Peter Stephenson
2005-10-03 16:50                         ` Bart Schaefer
2005-10-03  9:01                   ` DervishD
2005-10-03 16:21                     ` Bart Schaefer
2005-10-03 17:59                       ` DervishD
2005-10-04 16:31                         ` Bart Schaefer
2005-10-04 17:29                           ` DervishD
2005-10-04 17:34                             ` Peter Stephenson
2005-10-04 17:46                               ` DervishD
2005-10-01  8:01 DervishD
  -- strict thread matches above, loose matches on Subject: below --
2005-10-01  7:45 DervishD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1051001183818.ZM27904@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    --cc=zsh@dervishd.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).