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

Re: Exception handling and "trap" vs. TRAPNAL()



    Hi Peter :)

 * Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxx> 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...



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