zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-users@sunsite.dk
Subject: Re: Exception handling and "trap" vs. TRAPNAL()
Date: Fri, 30 Sep 2005 12:41:30 +0100	[thread overview]
Message-ID: <20050930124130.45eb0463.pws@csr.com> (raw)
In-Reply-To: <20050929200741.GA1156@DervishD>

DervishD <zsh@dervishd.net> 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 <pws@csr.com>                  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


  reply	other threads:[~2005-10-01 12:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-29 20:07 DervishD
2005-09-30 11:41 ` Peter Stephenson [this message]
2005-10-01 15:37   ` 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=20050930124130.45eb0463.pws@csr.com \
    --to=pws@csr.com \
    --cc=zsh-users@sunsite.dk \
    /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).