perlfunc
root
<P>
carp - warn of errors (from perspective of caller)
<P>
cluck - warn of errors with stack backtrace (not exported by default)
<P>
croak - die of errors (from perspective of caller)
<P>
confess - die of errors with stack backtrace
<P>
<HR>
<P>
<PRE> use Carp;
croak "We're outta here!";
</PRE>
<P>
<PRE> use Carp qw(cluck);
cluck "This is how we got here!";
</PRE>
<P>
<HR>
<P>
The Carp routines are useful in your own modules because they act like
<CODE>die()</CODE> or
<CODE>warn(),</CODE> but report where the error was in the code they were called from. Thus if you have a routine
<CODE>Foo()</CODE> that has a
<CODE>carp()</CODE> in it, then the
<CODE>carp()</CODE> will report the error as occurring where
<CODE>Foo()</CODE> was called, not where
<CODE>carp()</CODE> was called.
<P>
<HR>
<H2><A NAME="Forcing_a_Stack_Trace">Forcing a Stack Trace</A></H2>
<P>
As a debugging aid, you can force Carp to treat a croak as a confess and a
carp as a cluck across <EM>all</EM> modules. In other words, force a detailed stack trace to be given. This can
be very helpful when trying to understand why, or from where, a warning or
error is being generated.
<P>
This feature is enabled by 'importing' the non-existant symbol 'verbose'.
You would typically enable it by saying
<P>
<PRE> perl -MCarp=verbose script.pl
</PRE>
<P>
or by including the string <CODE>MCarp=verbose</CODE> in the <EM>PERL5OPT</EM>
environment variable.
<HR>