Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Perl: the Markov chain saw
 
PerlMonks  

Re: Error handling - how much/where/how?

by ruoso (Curate)
on Jun 13, 2005 at 10:10 UTC ( #466090=note: print w/ replies, xml ) Need Help??


in reply to Error handling - how much/where/how?

It's an option to use a common use error handling library. As sometimes giving the error on the return of the sub is not a good option (for example a sub that can return any value).

I use the Error library. It implements the try/catch syntax, enables printing the stack trace (as someone suggested on this thread) and doesn't require other things from people who use your module, since the exception is a regular die (with some info saved inside Error).

I like this approuch because it's easier to handle errors from methods that can throw many types of exceptions, you can programatically do something when *this* error and otherthing when *that* error very easy.

daniel


Comment on Re: Error handling - how much/where/how?
Re^2: Error handling - how much/where/how?
by xdg (Monsignor) on Jun 13, 2005 at 13:40 UTC

    You might want to be careful using Error. There can be some unexpected negative side-effects. Perrin's write up Re: Re2: Learning how to use the Error module by example has the details. (I've written Exception::Class::TryCatch to bring some try/catch sugar to the Exception::Class module, and you might consider that in place of Error.)

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Yeah, actually I had segfaults with Error prior to 0.15, but I'll consider switching to any other module, as Error is kindly to generate weird behaviour when you do something wrong... I just didn't know any good one...
      daniel

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://466090]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2014-04-18 13:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (468 votes), past polls