Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Error Reporting from Module

by Corion (Pope)
on Oct 09, 2019 at 07:23 UTC ( #11107230=note: print w/replies, xml ) Need Help??


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 ); }; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11107230]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2019-11-12 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (65 votes). Check out past polls.

    Notices?