Nov 23, 2009, 7:57 AM
Post #4 of 5
Re: [vishi] problem in error handling.
[In reply to]
You were probably thinking of this:
Don't use exit to abort a subroutine if there's any chance that someone might want to trap whatever error happened. Use die instead, which can be trapped by an eval.http://perldoc.perl.org/functions/exit.html
It's good advice, especially if you develop perl modules for general use; however, exit() has a couple of desirable features. 1) You can control (subject to OS/shell vagueries) the exit status of your program; and 2) unlike croak(), die(), etc., exit() doesn't slplat out a message to the console, which can be important if you want to evaluate your program's STDERR output. YMMV.
I suppose there's also a philosophical question here: Do you prefer to process errors by throwing and catching exceptions or by evaluating the return status of your subroutines? I prefer the latter. Hence, I almost never write a subroutine that intentionally dies() just to return an error.
(This post was edited by 1arryb on Nov 23, 2009, 8:33 AM)