http://www.perlmonks.org?node_id=384119


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