Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Idomatic Handling of Subroutine Error

by broquaint (Abbot)
on Sep 19, 2001 at 14:51 UTC ( [id://113289]=note: print w/replies, xml ) Need Help??


in reply to Idomatic Handling of Subroutine Error

Here's a rather funky example taken from the perl docs (man perlsub) that may provide a worthwhile solution -
sub try (&@) { my($try,$catch) = @_; eval { &$try }; if ($@) { local $_ = $@; &$catch; } } sub catch (&) { $_[0] } try { die "phooey"; } catch { /phooey/ and print "unphooey\n"; };
This is simliar to a lot of the above posts, in that it eval()s and then handles any errors. Although it's not *exactly* the sub wrapper you were looking for, I think it's a very cool alternative (but then again I'm impressed by all things functional ;o)
HTH

broquaint

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-03-29 05:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found