flipper has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, can anyone enlighten me as to why the exception in the example below is not caught by the bottom catch block?

cheers,


peter
#!/usr/bin/perl -w use strict; use Error qw(:try); my $foo=foo->new(); try{ $foo->foo(); }catch Error with { warn "i dont want to handle the error here"; }; package foo; sub new(){ return bless {}, "foo"; } sub foo($){ my $self=shift; try{ throw Error::Simple "handle me"; warn "success"; return; }catch Error with { warn "why does this never fire?"; }; }

Replies are listed 'Best First'.
Re: Error.pm not playing nicely with objects?
by adrianh (Chancellor) on Feb 03, 2006 at 13:58 UTC
    Dear monks, can anyone enlighten me as to why the exception in the example below is not caught by the bottom catch block?

    Because you aren't importing the try subroutines into your foo package :-)

    Add another  use Error qw(:try); after your package foo and it should work.

      thanks so much! i've spent hours and hours trying to figure this out. you're a star!!!
Re: Error.pm not playing nicely with objects?
by perrin (Chancellor) on Feb 03, 2006 at 13:52 UTC
    I'm not sure. Maybe a subtle problem with your try/catch syntax? I would try running this in the debugger to find out.