3 carp - warn of errors (from perspective of caller)
5 cluck - warn of errors with stack backtrace
6 (not exported by default)
8 croak - die of errors (from perspective of caller)
10 confess - die of errors with stack backtrace
12 shortmess - return the message that carp and croak produce
14 longmess - return the message that cluck and confess produce
19 croak "We're outta here!";
22 cluck "This is how we got here!";
24 print FH Carp::shortmess("This will have caller's details added");
25 print FH Carp::longmess("This will have stack backtrace added");
29 The Carp routines are useful in your own modules because
30 they act like die() or warn(), but with a message which is more
31 likely to be useful to a user of your module. In the case of
32 cluck, confess, and longmess that context is a summary of every
33 call in the call-stack. For a shorter message you can use carp,
34 croak or shortmess which report the error as being from where
35 your module was called. There is no guarantee that that is where
36 the error was, but it is a good educated guess.
38 You can also alter the way the output and logic of C<Carp> works, by
39 changing some global variables in the C<Carp> namespace. See the
40 section on C<GLOBAL VARIABLES> below.
42 Here is a more complete description of how shortmess works. What
43 it does is search the call-stack for a function call stack where
44 it hasn't been told that there shouldn't be an error. If every
45 call is marked safe, it then gives up and gives a full stack
46 backtrace instead. In other words it presumes that the first likely
47 looking potential suspect is guilty. Its rules for telling whether
48 a call shouldn't generate errors work as follows:
54 Any call from a package to itself is safe.
58 Packages claim that there won't be errors on calls to or from
59 packages explicitly marked as safe by inclusion in @CARP_NOT, or
60 (if that array is empty) @ISA. The ability to override what
61 @ISA says is new in 5.8.
65 The trust in item 2 is transitive. If A trusts B, and B
66 trusts C, then A trusts C. So if you do not override @ISA
67 with @CARP_NOT, then this trust relationship is identical to,
72 Any call from an internal Perl module is safe. (Nothing keeps
73 user modules from marking themselves as internal to Perl, but
74 this practice is discouraged.)
78 Any call to Carp is safe. (This rule is what keeps it from
79 reporting the error where you call carp/croak/shortmess.)
83 =head2 Forcing a Stack Trace
85 As a debugging aid, you can force Carp to treat a croak as a confess
86 and a carp as a cluck across I<all> modules. In other words, force a
87 detailed stack trace to be given. This can be very helpful when trying
88 to understand why, or from where, a warning or error is being generated.
90 This feature is enabled by 'importing' the non-existent symbol
91 'verbose'. You would typically enable it by saying
93 perl -MCarp=verbose script.pl
95 or by including the string C<MCarp=verbose> in the PERL5OPT
98 Alternately, you can set the global variable C<$Carp::Verbose> to true.
99 See the C<GLOBAL VARIABLES> section below.
101 =head1 GLOBAL VARIABLES
103 =head2 $Carp::CarpLevel
105 This variable determines how many call frames are to be skipped when
106 reporting where an error occurred on a call to one of C<Carp>'s
107 functions. For example:
109 $Carp::CarpLevel = 1;
110 sub bar { .... or _error('Wrong input') }
111 sub _error { Carp::carp(@_) }
113 This would make Carp report the error as coming from C<bar>'s caller,
114 rather than from C<_error>'s caller, as it normally would.
118 =head2 $Carp::MaxEvalLen
120 This variable determines how many characters of a string-eval are to
121 be shown in the output. Use a value of C<0> to show all text.
125 =head2 $Carp::MaxArgLen
127 This variable determines how many characters of each argument to a
128 function to print. Use a value of C<0> to show the full length of the
133 =head2 $Carp::MaxArgNums
135 This variable determines how many arguments to each function to show.
136 Use a value of C<0> to show all arguments to a function call.
140 =head2 $Carp::Verbose
142 This variable makes C<Carp> use the C<longmess> function at all times.
143 This effectively means that all calls to C<carp> become C<cluck> and
144 all calls to C<croak> become C<confess>.
146 Note, this is analogous to using C<use Carp 'verbose'>.
153 The Carp routines don't handle exception objects currently.
154 If called with a first argument that is a reference, they simply
155 call die() or warn(), as appropriate.