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

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



    Hi Peter :)

 * Peter Stephenson <pws@xxxxxxx> dixit:
> DervishD wrote:
> >     Just one note: why should be always blocks needed at all if you
> > can use this kind of solutions? As long as you don't cause ZERR to be
> > raised in "common_error()", this solution is much better because you
> > can fine tune (using the "trap" builtin) when do you want to do
> > common handling and when you don't. The only difference I can see is
> > that code in an always block is executed in the current environment
> > and code in "common_error()" is not.
> TRAP_RETURN triggers on any non-zero status, while an "always" block
> is used to stop actual errors which would usually cause everything in
> sight(*) to abort.  If you're really concerned only with non-zero status
> and don't care about errors there's every reason to go with something
> like TRAP_RETURN.

    But you can check for those kind of errors like this:

    ( #whatever would have caused an abortive-error )

    OK, you must run them in a subshell, but the fact is that this is
doable. But I see, an always block here is far more readable and easy
to use (apart from being more optimal if the 'abortive-error' can
happen in a loop).

    OTOH, code like this is very annoying when trapping ZERR:

    # If the file doesn't exist, this will raise ZERR
    # We probably will want ZERR raised if "do_something" fails,
    # but certainly not if the test fails. We must use "if"...
    [[ -r "$filename" ]] && do_something

    Thanks for the explanation :)

    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