Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Should I use carp/croak or warn/die

by haukex (Bishop)
on May 30, 2018 at 15:08 UTC ( #1215468=note: print w/replies, xml ) Need Help??

in reply to Should I use carp/croak or warn/die

Note that Carp doesn't automatically include a stack trace, that's only if you do perl -MCarp=verbose or $Carp::Verbose=1;, or you explicitly use confess. I like to use 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 confess to get the full stack trace.

$ cat 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 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 line 7. Foo::three() called at -e line 1

Replies are listed 'Best First'.
Re^2: Should I use carp/croak or warn/die
by SBECK (Chaplain) on May 30, 2018 at 15:27 UTC
    Thank you. I think you've just convinced me to use Carp, at least in some instances.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1215468]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2022-01-21 00:22 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (57 votes). Check out past polls.