Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Preffered Error notification?

by simeon2000 (Monk)
on Aug 05, 2002 at 17:58 UTC ( [id://187764]=note: print w/replies, xml ) Need Help??


in reply to Preferred Error notification?

sub myfunc { my $arg1 = shift or (die|warn) "missing arg in myfunc"; }

die or warn based on severity of missing argument. But that's just me.

--
perl -e "print qq/just another perl hacker who doesn't grok japh\n/"
simeon2000|http://holdren.net/

Replies are listed 'Best First'.
Re: Re: Preffered Error notification?
by ChemBoy (Priest) on Aug 05, 2002 at 18:07 UTC

    I'd say that this is precisely the situation that Carp is designed for--use carp or croak rather than warn and die, and they'll know which invocation of the function they messed up, which is generally fairly useful information.

    Alternatively, set $@, return undef, and let the caller figure out the problem. :-)



    If God had meant us to fly, he would *never* have given us the railroads.
        --Michael Flanders

      I rarely return undef explicitly, as it tends to do the wrong thing in list context. return by itself is shorter and smarter.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-19 20:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found