in reply to Error Reporting from Module
Personally, I like to use Carp::croak over die because it reports the problem on a line number that the module user can affect, instead of reporting the problem within a module that the module user will not edit/change.
I think your approach of having a reporting scheme that stores the error message and returns undef or (if "autodie" is set) croaks is the best approach:
sub _error { my( $self, $message ) = @_; $self->{last_error} = $message; croak $message if $self->{autodie}; }; sub do_something { my $res = eval { $webhook->execute(...); }; if( my $err = $@ ) { $self->_error( $err ); }; }
|
|---|