Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
laziness, impatience, and hubris
 
PerlMonks  

Re^2: the try/catch example from "Programming Perl" analyzed

by stvn (Monsignor)
on Aug 18, 2004 at 21:37 UTC ( #384119=note: print w/ replies, xml ) Need Help??


in reply to Re: the try/catch example from "Programming Perl" analyzed
in thread the try/catch example from "Programming Perl" analyzed

In Perl, you also have to handle the condition of a runtime error which is not an object

I believe that the try block is where the memory leak issues usually show up, since that is where the bulk of your working code is. But why throw catch away too?

sub catch (&) { if ($@) { my ($catch) = @_; my $e = $@; $e = My::Base::Exception->new($@) unless (ref($@) && UNIVERSAL::isa($@, "My::Base::Exception +")); $catch->($e); } } eval { die "test"; }; catch { my $e = shift; if ($e->isa('IOException')) { # ... } else { print $e; } };
I know chromatic would be upset that I am using UNIVERSAL::isa, but it will avoid your problem with using Scalar::Util::blessed, and as long as you don't use any other classes that override isa you should be okay.

-stvn


Comment on Re^2: the try/catch example from "Programming Perl" analyzed
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-04-20 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (487 votes), past polls