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

I am running a Tk program and need to capture all errors as they occur and feed them to a subroutine. Any suggestions on how to go about this are greatly appreciated. Everything I have found so far is to have the errors interact with the GUI and that is not what I want to do. Thanks in advance
  • Comment on Help !! I need to feed all errors to a subroutine

Replies are listed 'Best First'.
Re: need to feed all errors to a subroutine
by borisz (Canon) on Jun 30, 2004 at 00:10 UTC
    What errors do you mean? To capture die for example use eval.
    eval { # your code that may die }; if ( $@ ) { your_error_catcher( $@ ); }
    Boris
Re: need to feed all errors to a subroutine
by revdiablo (Prior) on Jun 30, 2004 at 00:22 UTC

    If you want to catch calls to die, then borisz has the answer for you, but if you want to capture warnings, you can use $SIG{'__WARN__'}. This allows you to install an arbitrary warning handler subroutine. You can read the details in perldoc -f warn.

      Pefect, thanks.
Re: Help !! I need to feed all errors to a subroutine
by bbfu (Curate) on Jun 30, 2004 at 07:12 UTC

    Since Tk already captures errors, you can simply use its built-in error handling function: Tk::Error. Just defined a sub as sub Tk::Error { ... } and process the errors as you wish.

    bbfu
    Black flowers blossom
    Fearless on my breath