zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Peter Stephenson <pws@pwstephenson.fsnet.co.uk>, zsh-workers@sunsite.dk
Subject: Re: Exception handling and "trap" vs. TRAPNAL()
Date: Sat, 01 Oct 2005 22:44:06 +0000	[thread overview]
Message-ID: <1051001224406.ZM28125@candle.brasslantern.com> (raw)
In-Reply-To: <20051001191035.2A4F48673@pwstephenson.fsnet.co.uk>

On Oct 1,  8:10pm, Peter Stephenson wrote:
}
} Bart Schaefer wrote:
} > So the question is:  Why ignore errors that occur in inline traps?
} 
} The answer to (1) is that traps are present as error handlers (of some
} sort and for some debatable value of "error") and to avoid confusing
} matters the error is taken from the code surrounding the trap, not the
} trap itself.

Yes, but the "error" of a non-zero command status is not the same as a
shell-level error (syntax or what have you).

} 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

It could be argued that, in the presence of an "always" block, the
function should not be considered to have "finished" at all.  The
shell-level error is supposed to have stopped execution; the implict
"return $?" never happened, the return status of the function is not
defined, and we're in no-man's land.

The trouble, of course, is that shell-level errors are not really
exceptions, an "always" block is not really an exception handler, and
nothing is actually "thrown" by "throw", so none of the assumptions
are valid that Raúl is making based on the names "throw" and "catch".
And the implementation simply can't stop execution and unwind to the
"always" block the way a real exception system would.
 
} You can certainly argue that the "normal effect" of a ZERR trap is not
} to cause an error, and it's certainly possible to argue that yet more
} hacked-up special cases and additional bug-prone complexity in the trap
} code are warranted.

Well, that's just it.  An even stronger argument than the no-man's land
proposition, is that errflag should *not* be propagated out of a ZERR
trap.  This would not accomplish what Raúl wants, because it would mean
that *neither* TRAPZERR nor "trap ... ZERR" would be capable of "raising
an exception" -- in effect we'd be removing a special-case, not adding
one.

    } else if (trapreturn >= 0 && !isfunc) {
	/*
	 * Context was an inline trap.  If an explicit return value
	 * was used, we need to set `lastval'.  Otherwise we use the
	 * value restored by execrestore.  In this case, all return
	 * values indicate an explicit return from the current function,
	 * so always handle specially.  trapreturn is always restored by
	 * execrestore.
	 */
	trapret = trapreturn + 1;
    } else if (errflag)
	trapret = 1;

I'm not sure, though, that there isn't some other kind of real signal
that depends on that snippet.

} However, I'm still not convinced this is going anywhere I want to go.

The behavior should be consistent, is all.


  parent reply	other threads:[~2005-10-01 22:44 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
2005-10-01 22:44         ` Bart Schaefer [this message]
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=1051001224406.ZM28125@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --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).