NAME
MooseX::Exception::Base - Base class for exceptions
VERSION
This documentation refers to MooseX::Exception::Base version 0.0.6.
SYNOPSIS
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;
}
DESCRIPTION
This module provides basic helpers to make Moose exception objects, is is somewhat similar to Exception::Class in usage.
SUBROUTINES/METHODS
throw (%args)
-
Throw an exception with object with the parameters from
%args
verbose ([$verbosity])
-
Stringifys the exception object, if
$verbosidy
is not passed the classes attribute _verbose is used.
DIAGNOSTICS
CONFIGURATION AND ENVIRONMENT
DEPENDENCIES
INCOMPATIBILITIES
BUGS AND LIMITATIONS
There are no known bugs in this module.
Please report problems to Ivan Wills (ivan.wills@gmail.com).
Patches are welcome.
ALSO SEE
Throwable probably should be use rather than this module for new projects as it's now best practice.
AUTHOR
Ivan Wills - (ivan.wills@gmail.com)
CONTRIBUTORS
Adam Herzog - adam@adamherzog.com
LICENSE AND COPYRIGHT
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.