* Fwd: [Exception handling and "trap" vs. TRAPNAL()]
@ 2005-09-30 18:44 DervishD
2005-10-01 16:22 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: DervishD @ 2005-09-30 18:44 UTC (permalink / raw)
To: Zsh Workers
Hi all :)
I'm forwarding this message here after looking at the zsh-workers
mail archive. There have been problems with "trap" in the past,
specially when saving/restoring state, and this problem is maybe
caused by this (or my stupidity, who knows...).
Thanks a lot in advance :)
----- Forwarded message from DervishD <zsh@dervishd.net> -----
> Date: Thu, 29 Sep 2005 22:07:41 +0200
> From: DervishD <zsh@dervishd.net>
> To: Zsh Users <zsh-users@sunsite.dk>
> Subject: Exception handling and "trap" vs. TRAPNAL()
>
> Hi all :)
>
> Let's say we have this script, using exception handling:
>
> --- cut here ---
> #!/bin/zsh
>
> emulate -L zsh
>
> [[ "$1" = "trap" ]] && trap 'throw DEFAULT' ZERR
> [[ "$1" = "TRAPZERR" ]] && function TRAPZERR() { throw DEFAULT ; }
>
> function throw() {
> typeset -g EXCEPTION="$1"
> readonly THROW=0
> if (( TRY_BLOCK_ERROR == 0 )); then
> (( TRY_BLOCK_ERROR = 1 ))
> fi
> THROW= 2>/dev/null
> }
>
> function catch() {
> typeset -g CAUGHT
> if [[ $TRY_BLOCK_ERROR -gt 0 && $EXCEPTION = ${~1} ]]; then
> (( TRY_BLOCK_ERROR = 0 ))
> CAUGHT="$EXCEPTION"
> unset EXCEPTION
> return 0
> fi
> return 1
> }
>
> alias catch="noglob catch"
>
>
> {
> 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 ---
>
> Sorry for the size, but I want to make sure it is as
> self-contained as possible. Well, I do the following:
>
> $ ./script trap
> Before throwing
> Caught exception EXCEPTION
>
> $ ./script TRAPZERR
> Before throwing
> Caught exception DEFAULT
>
> $ ./script
> 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?
>
> AFAIK the "trap" builtin runs its arguments in the current
> environment, so to say it's like an alias, like cutting and pasting
> the code, but anyway that shouldn't be the problem, since "throw" is
> using globals and so it affects running in any environment.
>
> The only thing that could be happening is that the ZERR trap
> using "trap" is not setting "TRY_BLOCK_ERROR" to "1", or it sets the
> variable but the variable gets reset upon exiting the trap :???
>
> Can anybody (and I really mean anybody, not Bart XD) explain this
> to me? I would like to use something similar and I need to use "trap"
> traps and not "TRAPNAL()" traps because I want to use LINENO and
> probably a couple of variables which are local to the functions where
> the ZERR trap can be raised.
>
> Thanks a lot in advance :)
>
> 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...
>
>
----- End forwarded message -----
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...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Fwd: [Exception handling and "trap" vs. TRAPNAL()]
2005-09-30 18:44 Fwd: [Exception handling and "trap" vs. TRAPNAL()] DervishD
@ 2005-10-01 16:22 ` Bart Schaefer
2005-10-01 17:24 ` DervishD
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2005-10-01 16:22 UTC (permalink / raw)
To: DervishD, Zsh Workers
On Sep 30, 8:44pm, DervishD wrote:
}
} I'm forwarding this message here after looking at the zsh-workers
} mail archive.
You don't need to do this. *ALL* zsh-users messages are forwarded to
the zsh-workers list; you can't be on zsh-workers without receiving
the mail from zsh-users. They just aren't archived with zsh-workers.
Except now it's archived three times. Mailing lists are not always
instantaneous, especially on month boundaries when the servers may be
doing housekeeping.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Fwd: [Exception handling and "trap" vs. TRAPNAL()]
2005-10-01 16:22 ` Bart Schaefer
@ 2005-10-01 17:24 ` DervishD
0 siblings, 0 replies; 3+ messages in thread
From: DervishD @ 2005-10-01 17:24 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Zsh Workers
Hi Bart :)
* Bart Schaefer <schaefer@brasslantern.com> dixit:
> On Sep 30, 8:44pm, DervishD wrote:
> } I'm forwarding this message here after looking at the zsh-workers
> } mail archive.
> You don't need to do this. *ALL* zsh-users messages are forwarded to
> the zsh-workers list; you can't be on zsh-workers without receiving
> the mail from zsh-users. They just aren't archived with zsh-workers.
I knew about the mailinglist nesting, but since I didn't see them
archived in zsh-workers, I assumed they didn't arrive on the list :(
> Except now it's archived three times. Mailing lists are not always
> instantaneous, especially on month boundaries when the servers may
> be doing housekeeping.
Here I blindly assumed that an one-day lag was too much to be
just normal delay, so I thought that crossposting was not allowed, or
maybe forwarding was disabled or something like that.
Really, sorry for the noise O:( Obviously I didn't mean to flood
the list with my messages.
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...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-10-01 17:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-30 18:44 Fwd: [Exception handling and "trap" vs. TRAPNAL()] DervishD
2005-10-01 16:22 ` Bart Schaefer
2005-10-01 17:24 ` DervishD
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).