Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

(ichimunki) Re: Idomatic Handling of Subroutine Error

by ichimunki (Priest)
on Sep 18, 2001 at 23:01 UTC ( [id://113178]=note: print w/replies, xml ) Need Help??


in reply to Idomatic Handling of Subroutine Error

You can always test for results and return an undef on failure, which will make both of your last examples work.

You might want to consider handling as much of the error in the sub itself as possible, that is, your first example may as well do the if-then work inside the sub so that you don't have to write handlers for it every time you call the sub. The main thing you'd want to have in your calling block is logic to protect the rest of the block from a failure in the sub... but the warning should be issued from the place where it occurred if at all possible.
  • Comment on (ichimunki) Re: Idomatic Handling of Subroutine Error

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found