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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.