note
haukex
<p>Note that [doc://Carp] doesn't automatically include a stack trace, that's only if you do <c>perl -MCarp=verbose script.pl</c> or <c>$Carp::Verbose=1;</c>, or you explicitly use <c>confess</c>. I like to use [doc://Carp] in my modules because it reports the error as coming from the user's code, rather than the module itself, which makes more sense for many error cases (like incorrect parameters). When it's an internal error that I don't expect the user to see (at least not often), I'll sometimes use <c>confess</c> to get the full stack trace.</p>
<c>
$ cat Foo.pm
package Foo;
use warnings;
use strict;
use Carp;
sub one { die "Bad call to one"; }
sub two { carp "Bad call to two"; }
sub three { confess "Some error in three"; }
1;
$ perl -I. -MFoo -le 'Foo::one'
Bad call to one at Foo.pm line 5.
$ perl -I. -MFoo -le 'Foo::two'
Bad call to two at -e line 1.
$ perl -I. -MFoo -le 'Foo::three'
Some error in three at Foo.pm line 7.
Foo::three() called at -e line 1
</c>
1215465
1215465