1Carp(3pm)              Perl Programmers Reference Guide              Carp(3pm)
2
3
4

NAME

6       carp    - warn of errors (from perspective of caller)
7
8       cluck   - warn of errors with stack backtrace
9                 (not exported by default)
10
11       croak   - die of errors (from perspective of caller)
12
13       confess - die of errors with stack backtrace
14
15       shortmess - return the message that carp and croak produce
16
17       longmess - return the message that cluck and confess produce
18

SYNOPSIS

20           use Carp;
21           croak "We're outta here!";
22
23           use Carp qw(cluck);
24           cluck "This is how we got here!";
25
26           print FH Carp::shortmess("This will have caller's details added");
27           print FH Carp::longmess("This will have stack backtrace added");
28

DESCRIPTION

30       The Carp routines are useful in your own modules because they act like
31       die() or warn(), but with a message which is more likely to be useful
32       to a user of your module.  In the case of cluck, confess, and longmess
33       that context is a summary of every call in the call-stack.  For a
34       shorter message you can use carp, croak or shortmess which report the
35       error as being from where your module was called.  There is no guaran‐
36       tee that that is where the error was, but it is a good educated guess.
37
38       You can also alter the way the output and logic of "Carp" works, by
39       changing some global variables in the "Carp" namespace. See the section
40       on "GLOBAL VARIABLES" below.
41
42       Here is a more complete description of how shortmess works.  What it
43       does is search the call-stack for a function call stack where it hasn't
44       been told that there shouldn't be an error.  If every call is marked
45       safe, it then gives up and gives a full stack backtrace instead.  In
46       other words it presumes that the first likely looking potential suspect
47       is guilty.  Its rules for telling whether a call shouldn't generate
48       errors work as follows:
49
50       1.  Any call from a package to itself is safe.
51
52       2.  Packages claim that there won't be errors on calls to or from pack‐
53           ages explicitly marked as safe by inclusion in @CARP_NOT, or (if
54           that array is empty) @ISA.  The ability to override what @ISA says
55           is new in 5.8.
56
57       3.  The trust in item 2 is transitive.  If A trusts B, and B trusts C,
58           then A trusts C.  So if you do not override @ISA with @CARP_NOT,
59           then this trust relationship is identical to, "inherits from".
60
61       4.  Any call from an internal Perl module is safe.  (Nothing keeps user
62           modules from marking themselves as internal to Perl, but this prac‐
63           tice is discouraged.)
64
65       5.  Any call to Carp is safe.  (This rule is what keeps it from report‐
66           ing the error where you call carp/croak/shortmess.)
67
68       Forcing a Stack Trace
69
70       As a debugging aid, you can force Carp to treat a croak as a confess
71       and a carp as a cluck across all modules. In other words, force a
72       detailed stack trace to be given.  This can be very helpful when trying
73       to understand why, or from where, a warning or error is being gener‐
74       ated.
75
76       This feature is enabled by 'importing' the non-existent symbol 'ver‐
77       bose'. You would typically enable it by saying
78
79           perl -MCarp=verbose script.pl
80
81       or by including the string "MCarp=verbose" in the PERL5OPT environment
82       variable.
83
84       Alternately, you can set the global variable $Carp::Verbose to true.
85       See the "GLOBAL VARIABLES" section below.
86

GLOBAL VARIABLES

88       $Carp::CarpLevel
89
90       This variable determines how many call frames are to be skipped when
91       reporting where an error occurred on a call to one of "Carp"'s func‐
92       tions. For example:
93
94           $Carp::CarpLevel = 1;
95           sub bar     { .... or _error('Wrong input') }
96           sub _error  { Carp::carp(@_) }
97
98       This would make Carp report the error as coming from "bar"'s caller,
99       rather than from "_error"'s caller, as it normally would.
100
101       Defaults to 0.
102
103       $Carp::MaxEvalLen
104
105       This variable determines how many characters of a string-eval are to be
106       shown in the output. Use a value of 0 to show all text.
107
108       Defaults to 0.
109
110       $Carp::MaxArgLen
111
112       This variable determines how many characters of each argument to a
113       function to print. Use a value of 0 to show the full length of the
114       argument.
115
116       Defaults to 64.
117
118       $Carp::MaxArgNums
119
120       This variable determines how many arguments to each function to show.
121       Use a value of 0 to show all arguments to a function call.
122
123       Defaults to 8.
124
125       $Carp::Verbose
126
127       This variable makes "Carp" use the "longmess" function at all times.
128       This effectively means that all calls to "carp" become "cluck" and all
129       calls to "croak" become "confess".
130
131       Note, this is analogous to using "use Carp 'verbose'".
132
133       Defaults to 0.
134

BUGS

136       The Carp routines don't handle exception objects currently.  If called
137       with a first argument that is a reference, they simply call die() or
138       warn(), as appropriate.
139
140
141
142perl v5.8.8                       2001-09-21                         Carp(3pm)
Impressum