in reply to Why doesn't' eval{} trap die() when using File::Find?

After fixing the compile errors, eval properly catches the exceptions.
use File::Find; my @dirlist = ('.', '.', 'nonexistant'); foreach my $dir (@dirlist){ eval { find( \&wanted, $dir ) }; # Does NOT work when passing +a reference to foo to the find module # eval { bar() }; # DOES work when just calling a subroutine dir +ectly if( $@ ){ print "$dir had error: ".$@; } else { print "processed $dir\n"; } } sub wanted{ die "haha!"; } sub bar{ die "haha!"; }
. had error: haha! at a.pl line 18. . had error: haha! at a.pl line 18. processed nonexistant

In what way does it not work for you? Could it be that your version of F::F actually catches the exceptions?

Replies are listed 'Best First'.
Re^2: Why doesn't' eval{} trap die() when using File::Find?
by Sukotto (Novice) on Aug 04, 2010 at 17:52 UTC
    It works now, of course.
    Was it a PEBKAC error?.
    Thank you for your help.