Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Exception handling and "trap" vs. TRAPNAL()
- X-seq: zsh-workers 21839
- From: DervishD <zsh@xxxxxxxxxxxx>
- To: Peter Stephenson <pws@xxxxxxx>
- Subject: Re: Exception handling and "trap" vs. TRAPNAL()
- Date: Tue, 4 Oct 2005 19:46:04 +0200
- Cc: zsh-workers@xxxxxxxxxx
- In-reply-to: <EXCHANGE03sdEmM3sw800001ff8@xxxxxxxxxxxxxxxxxx>
- Mail-followup-to: Peter Stephenson <pws@xxxxxxx>, zsh-workers@xxxxxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- Organization: DervishD
- References: <20051002190940.437F9866F@xxxxxxxxxxxxxxxxxxxxxxxx> <1051002195518.ZM2163@xxxxxxxxxxxxxxxxxxxxxxx> <20051002230027.GA194@DervishD> <1051003013758.ZM3107@xxxxxxxxxxxxxxxxxxxxxxx> <20051003090121.GC278@DervishD> <1051003162109.ZM4533@xxxxxxxxxxxxxxxxxxxxxxx> <20051003175913.GB3231@DervishD> <1051004163144.ZM32294@xxxxxxxxxxxxxxxxxxxxxxx> <20051004172910.GA21195@DervishD> <EXCHANGE03sdEmM3sw800001ff8@xxxxxxxxxxxxxxxxxx>
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