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

Discussion in 'Perl Misc' started by Peter Wyzl, Aug 1, 2005.

  1. Peter Wyzl

    Peter Wyzl Guest

    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
    --
    print "Just another Perl Hacker";
     
    Peter Wyzl, Aug 1, 2005
    #1
    1. Advertising

  2. Peter Wyzl

    Anno Siegel Guest

    Peter Wyzl <> wrote in comp.lang.perl.misc:
    > 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
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
     
    Anno Siegel, Aug 1, 2005
    #2
    1. Advertising

  3. Re: Suppressing Output (Was: croak)

    Anno Siegel wrote:
    > Peter Wyzl <> wrote in comp.lang.perl.misc:
    >> I have a program using Win32::FileSecurity which has a known bug, in
    >> that it croaks rather than reporting errors via $! as it documents.
    >> <snip>
    >> How can I prevent the croak? Is there some way to trap it?

    > 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.

    --
    With kind regards Veli-Pekka Tätilä ()
    Accessibility, game music, synthesizers and programming:
    http://www.student.oulu.fi/~vtatila/
     
    Veli-Pekka Tätilä, Aug 1, 2005
    #3
  4. Peter Wyzl

    Peter Wyzl Guest

    "Anno Siegel" <-berlin.de> wrote in message
    news:dckjnf$dka$-Berlin.DE...
    : Peter Wyzl <> wrote in comp.lang.perl.misc:
    : > 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... :)

    --
    P
    --
    print "Just another Perl Hacker";
     
    Peter Wyzl, Aug 1, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lloyd Sheen

    Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    457
    Natty Gur
    Jan 26, 2004
  2. Lloyd Sheen

    More Die IDE Die

    Lloyd Sheen, Jan 24, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    470
    Alvin Bruney
    Jan 25, 2004
  3. Irving Kimura

    Why Carp::croak over die?

    Irving Kimura, May 13, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    527
    Irving Kimura
    May 14, 2004
  4. Michael TEpperis

    problems with croak

    Michael TEpperis, Jun 3, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    142
    John Bokma
    Jun 3, 2004
  5. John Bokma

    croak conventions in methods?

    John Bokma, Nov 17, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    99
    John Bokma
    Nov 18, 2004
Loading...

Share This Page