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