CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced: Re: [vishi] problem in error handling.: Edit Log



1arryb
User

Nov 23, 2009, 7:57 AM


Views: 3543
Re: [vishi] problem in error handling.

vishi,

You were probably thinking of this:

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

Update:

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.

Cheers,

Larry


(This post was edited by 1arryb on Nov 23, 2009, 8:33 AM)


Edit Log:
Post edited by 1arryb (User) on Nov 23, 2009, 8:19 AM
Post edited by 1arryb (User) on Nov 23, 2009, 8:31 AM
Post edited by 1arryb (User) on Nov 23, 2009, 8:33 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives