Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Don't die() while executing a subroutine or method. Only the main module can die() if something goes wrong. Nobody can predict where the class will be used, so an unexpected die() can break the caller's logic.

How about looking at it more like this? The sub or method is a table saw. With the logic above, only the operator can decide to turn the saw off, i.e., die. For the logic to work reasonably, the main program must have all knowledge of all internal code paths and wrinkles to know when die is appropriate. This is obviously unreasonable and untenable except in the most trivial case. It’s too likely to get through a huge execution chain with a bad result without having any idea where it went bad. Or why it’s harder to turn the saw off when your fingers are on the floor. So, for my part–

Die early, die often (using Carp as suggested elsewhere). This is why, I’d guess, nearly every single experienced monk here would tell you to set RaiseError => 1 in your DBI handles. Again, consistency is always the most important part whichever road you take.


In reply to Re: Best practices for handling errors by Your Mother
in thread Best practices for handling errors by v_melnik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-25 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found