MooseX::Exception::Base - Base class for exceptions
This documentation refers to MooseX::Exception::Base version 0.0.6.
package MyException; use Moose; extends 'MooseX::Exception::Base'; has code => ( is => 'rw', isa => 'Num' ); package MyOtherException; use Moose; extends 'MooseX::Exception::Base'; has message => ( is => 'rw', isa => 'Str', traits => [qw{MooseX::Exception::Stringify}], stringify_pre => 'prefix string ', stringify_post => ' postfix string', # a subroutine that returns a stringified value eg custom DateTime formatting stringify => sub {return $_}, ); # ... else where use MyException; sub mysub { MyException->throw( error => 'My error', code => 666 ); } eval { mysub() }; if ($@) { warn "ERROR : $e\n"; # or warn $e->verbose; } sub myother { MyOtherException->throw( message => "Custom error message", ); } eval { myother() }; if ($@) { warn "ERROR : $e\n"; # or warn $e->verbose; }
This module provides basic helpers to make Moose exception objects, is is somewhat similar to Exception::Class in usage.
throw (%args)
Throw an exception with object with the parameters from %args
%args
verbose ([$verbosity])
Stringifys the exception object, if $verbosidy is not passed the classes attribute _verbose is used.
$verbosidy
There are no known bugs in this module.
Please report problems to Ivan Wills (ivan.wills@gmail.com).
Patches are welcome.
Throwable probably should be use rather than this module for new projects as it's now best practice.
Moose, Exception::Class
Ivan Wills - (ivan.wills@gmail.com)
Adam Herzog - adam@adamherzog.com
Copyright (c) 2012 Ivan Wills (14 Mullion Close Hornsby Heights NSW Australia 2077). All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To install MooseX::Exception::Base, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Exception::Base
CPAN shell
perl -MCPAN -e shell install MooseX::Exception::Base
For more information on module installation, please visit the detailed CPAN module installation guide.