Exception::Chain - It's chained exception module
use Exception::Chain; eval { process($params); }; if (my $e = $@) { if ($e->match('critical')) { logging($e->to_string); # can not connect server at get_user line [A]. dbname=user is connection failed at get_user line [B]. request_id : [X] at process line [C]. } if ($e->match('critical', 'internal server error')) { # or send_email($e->to_string); } if (my $error_response = $e->delivery) { return $error_response; } else { return HTTP::Response->(500, 'unknown error'); } } sub process { my ($params) = @_; eval { get_user($params->{user_id}); }; if (my $e = $@) { Exception::Chain->throw( error => $e, tag => 'internal server error', message => sprintf('params : %s', $params->as_string), delivery => HTTP::Response->(500, 'internal server error'), ); } } sub get_user { my ($user_id) = @_; eval { # die 'can not connect server', }; if (my $e = $@) { Exception::Chain->throw( tag => 'critical', message => 'database error', error => $e, ); } }
Exception::Chain is chained exception module
store a following value.
throw($e); # Exception::Chain instance or message throw( tag => 'critical', message => 'connection failed', ) throw( tag => ['critical', 'database error'], message => 'connection failed', ) throw( tag => ['critical', 'database error'], message => 'connection failed', error => $@ ) throw( tag => ['critical', 'database error'], message => 'connection failed', delivery => HTTP::Response->new( 500, 'internal server error' ), )
rethrow exception object.
chained log.
first message.
matching stored tag.
delivered object. (or scalar object)
$Exception::Chain::SkipDepth
Copyright (C) Hiroyoshi Houchi.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Hiroyoshi Houchi <git@hixi-hyi.com>
To install Exception::Chain, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Exception::Chain
CPAN shell
perl -MCPAN -e shell install Exception::Chain
For more information on module installation, please visit the detailed CPAN module installation guide.