On 8/13/07, Robert Hicks <[EMAIL PROTECTED]> wrote:

> I typically "use Carp;" and change my "die" and "warn" statements to
> "croak" and "carp". I have read a couple places croak/carp are a little
> better at telling you what and where than the standard die/warn.

If to Carp is wrong, I don't want to be right.

But you don't use them because they're "a little better", but because
they're "the right tool for the job". Using croak or carp reports the
error itself in much the same way as die or warn would, but they point
the finger of blame at your module's caller. That is to say, if my
code calls a subroutine in your module, and your subroutine in turn
calls croak, then the error message is going to identify the bug as
having occurred in MY code, instead of yours. The line number and file
name report where I called your code. (See the Carp docs for the full
story.)

So, if you're trying to say, "you've misused my module", then carp and
croak are the way to do it.

If, on the other hand, you're trying to say, "something unexpected
happened, and my code wasn't prepared to deal with it", perhaps warn
and die will be more appropriate. It all depends, in the end, upon how
you can best assist the person who will be unfortunate enough to see
the error message.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to