I thought the use of carp/croak was fairly intuitive when I first saw it (after running it to see the output):

For example; At the beginning of a sub, sanity check the input and carp/croak if it is bad (too many, too few, invalid data, wrong reference type, etc). Then roll along, and use warn/die when things the sub does go wrong. If in doubt, warn/die.

The key thing IMO being to make sure that when carp/croaking, the caller knows what you're talking about. If your error message refers to a parameter or lack thereof, carp/croak makes sense.
The Bar() sub could carp/croak with the following message, for example:
"Unmatched parentheses in Parameter 1 at file Foo line 42:  $Answer = Bar('(2+5))*5');"
And that makes perfect sense as an error message.

"Failed to open log file for write" on the other hand, is not the caller's fault. Unless one of your parameters was a filehandle to use as a log, they will have no idea what the message is talking about. If you were passed in a filehandle for that purpose, the message could be better written as
"Log filehandle in Parameter 5 could not be opened for write"


In reply to Re: Replacing warn/die with carp/croak? by SuicideJunkie
in thread Replacing warn/die with carp/croak? by dragonchild

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.