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

hi, I'm using something like the following :
my $io = io 'file.txt';
The problem is that I want to capture the error message and handle it according to my logic.
I cant do :
eval { my = io 'file.txt' }; if $@ ..
because the IO::All handles this internally.
And for that matter is there a way to intercept Carp.pm errors in some way in a central place and handle it myself ?
thanx

Replies are listed 'Best First'.
Re: handling Carp errors ?
by bobf (Monsignor) on Nov 03, 2006 at 18:31 UTC

    From the docs for IO::All, it looks like there are a couple of possibilities that might help you do what you want:

    • errors
      Use this to set a subroutine reference that gets called when an internal error is thrown.
    • throw
      This is an internal method that gets called whenever there is an error. It could be useful to override it in a subclass, to provide more control in error handling.

    Update: after looking at the source, I think you are going to want to subclass throw:

    sub throw { my $self = shift; require Carp; ; return &{$self->errors}(@_) if $self->errors; return Carp::confess(@_) if $self->_confess; return Carp::croak(@_); }