How do I prevent croak in a module from making my script die?

P

Peter Wyzl

I have a program using Win32::FileSecurity which has a known bug, in that it
croaks rather than reporting errors via $! as it documents. I am trying to
run a process agains multiple directories where I expect to encounter some
errors, but Win32::FileSecurity croaks when it encounters the errors. How
can I prevent the croak? Is there some way to trap it? I have looked into
perlfaq8 about trapping signals but I don't see that I can apply it to my
situation.

My script is only slightly modified from the example in the docs:

#!/perl -w
use strict;

# Gets the rights for all files listed on the command line.
use Win32::FileSecurity qw(Get EnumerateRights);

opendir (DIR, '.') or die "Unable to read directory $!\n";
my @dirs;
while (my $dir = readdir DIR){
next unless -d $dir;
push @dirs, $dir;
}
closedir DIR;

foreach( @dirs ) {
next unless -e $_ ;
print "$_\n";
my (%hash, @happy);
if ( Get( $_, \%hash ) ) { # Croaks Here on some dirs
while( my($name, $mask) = each %hash ) {
print "$name:\n\t";
EnumerateRights( $mask, \@happy ) ;
print join( "\n\t", @happy ), "\n";
}
}
else {
print( "Error #", int( $! ), ": $!" ) ; # Never gets here
}
}


Any suggestions or pointers to further reading would be most appreciated.

P
 
A

Anno Siegel

Peter Wyzl said:
I have a program using Win32::FileSecurity which has a known bug, in that it
croaks rather than reporting errors via $! as it documents. I am trying to
run a process agains multiple directories where I expect to encounter some
errors, but Win32::FileSecurity croaks when it encounters the errors. How
can I prevent the croak? Is there some way to trap it? I have looked into
perlfaq8 about trapping signals but I don't see that I can apply it to my
situation.

perldoc -f eval.

Anno
 
V

Veli-Pekka Tätilä

Anno said:
perldoc -f eval.

On a side note, I had a sort of similar problem recently and also found a
solution. It didn't die in my case but the Acme::Turing module seems to
always output the machine steps when I only wanted to see the final memory
contents.
Recalling that DOS had a NULL device, too, I opened a NULL file:
open NULL, '>NULL' or die;
And selected it as the default output file handle:
select NULL;
Finally, I said select STDOUT; to get normal printing working again.
Works like a charm.

Hope this can help someone.
 
P

Peter Wyzl

: > I have a program using Win32::FileSecurity which has a known bug, in
that it
: > croaks rather than reporting errors via $! as it documents. I am trying
to
: > run a process agains multiple directories where I expect to encounter
some
: > errors, but Win32::FileSecurity croaks when it encounters the errors.
How
: > can I prevent the croak? Is there some way to trap it? I have looked
into
: > perlfaq8 about trapping signals but I don't see that I can apply it to
my
: > situation.
:
: perldoc -f eval.

Thanks Anno. Too long away from the command line it seems... :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top