Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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.


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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2015-11-29 22:04 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (753 votes), past polls