zsh-workers
 help / color / mirror / code / Atom feed
From: DervishD <zsh@dervishd.net>
To: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>
Cc: zsh-workers@sunsite.dk
Subject: Re: Exception handling and "trap" vs. TRAPNAL()
Date: Sat, 1 Oct 2005 22:41:52 +0200	[thread overview]
Message-ID: <20051001204152.GB134@DervishD> (raw)
In-Reply-To: <20051001191035.2A4F48673@pwstephenson.fsnet.co.uk>

    Hi Peter :)

 * Peter Stephenson <pws@pwstephenson.fsnet.co.uk> dixit:
> The answer to (2) is this, from the manual regarding function-style traps:
> 
>   The return status from the function is handled specially.  If it
>   is  zero, the signal is assumed to have been handled, and execu‐
>   tion continues normally.  Otherwise, the normal  effect  of  the
>   signal  is  produced; if this causes execution to terminate, the
>   status returned to the shell is the  status  returned  from  the
>   function.
> 
> So the whole behaviour that DervishD is seeing is a side affect of the
> fact that this:
> 
>   TRAPZERR() { throw DEFAULT; }
> 
> finishes by executing a command with non-zero status, the throw, causing
> the special behaviour described above.

    But I didn't see that as a side effect, since the trap is not
returning. I assumed that the "throw" broke execution flow, and
jumped to the start of the "always" block, that is, no return value
from TRAPZERR was involved.

    I know, the code I was proposing is weird, and ZERR is intended
to *handle* errors, not to throwing exceptions, but if inline traps
won't cause an "always" block to be run, it should be stated in the
manual (IMHO). Probably ZERR is a bad example, but as soon as I
started to mess with exceptions and "always" blocks I thought about a
trap for SIGINT to do cleanup, using an exception and some "always"
blocks. Probably people is not using exception handling in shell
script, but if the feature exits, it should work seamlessly with
traps or at least document the problem.

    On the other hand, I don't see any problem in traps not causing
exceptions to be thrown, but the behaviour should be consistent and
both kinds of traps should behave the same. Otherwise you can write
code using function traps and throwing exceptions from the trap, and
as soon as you need the trap to be inline (for using $LINENO or any
other similar variable) your code will no longer work :(

    Anyway, thanks a lot for explaining the problem and the decisions
behind the behaviour. As I suspected and told to Bart, I wasn't sure
this was a bug.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


  reply	other threads:[~2005-10-01 20:41 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
2005-10-01 19:10       ` Peter Stephenson
2005-10-01 20:41         ` DervishD [this message]
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=20051001204152.GB134@DervishD \
    --to=zsh@dervishd.net \
    --cc=pws@pwstephenson.fsnet.co.uk \
    --cc=zsh-workers@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).