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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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


Nov 23, 2009, 7:57 AM

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


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.

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)

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