Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: About zsh-users 8489 (exception handling)

    Hi Bart :)

    You came to the rescue, as always ;)

 * Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> dixit:
> On Sep 28,  1:47am, DervishD wrote:
> :
> :     In zsh-users 8489 Bart Schaeffer proposes using this syntax:
> : 
> :     { ${:?THROW} } 2>/dev/null
> : 
> :     Unfortunately, that doesn't work because ${:?...} *exits* from
> : the shell
> Not in an interactive shell, it doesn't.  However ...

    But I use (or will use) throw mainly in scripts, and that makes
the script to exit. And probably the 90% of throw/catch usage will
take place in scripts, not in interactive shells...
> : Is there any other way of generating an error (the exception) without
> : using a subshell and without using current invalid syntax that could
> : become valid in the future?
> Yes.  If you declare (at the top of the throw function)
>     readonly THROW
> then
>     THROW= 2>/dev/null
> causes the error, which can be caught with "always".  You don't even
> need the extra layer of { }.  I like this a lot, because it uses only
> valid syntax that is pretty much guaranteed always to remain valid.

    That's VERY clever, dude :))) I like this solution a lot :)

> I think EXCEPTION should also be declared with "typeset -g", so that
> makes the complete function look like:

    But the function will work correctly even without "typeset -g",
wouldn't it? Wouldn't be needed "typeset -g" in "catch" too for the
CAUGHT parameter?

    Thanks a lot for your answer :)

    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...

Messages sorted by: Reverse Date, Date, Thread, Author