Name
Unexpected::TraitFor::ExceptionClasses - Define an exception class hierarchy
Synopsis
package YourExceptionClass;
use Moo;
extends 'Unexpected';
__PACKAGE__->has_exception( 'A' );
__PACKAGE__->has_exception( 'B', { parents => 'A' } );
__PACKAGE__->has_exception( 'C', 'A' ); # same but shorter
__PACKAGE__->has_exception( 'D', [ 'B', 'C' ] ); # diamond pattern
# Then elsewhere
__PACKAGE__->throw( 'error message', { class => 'C' } );
# Elsewhere still
my $e = __PACKAGE__->caught;
$e->class eq 'C'; # true
$e->instance_of( 'A' ); # true
$e->instance_of( 'B' ); # false
$e->instance_of( 'C' ); # true
$e->instance_of( 'D' ); # false
Version
This documents version v0.12.$Rev: 1 $ of Unexpected::TraitFor::ExceptionClasses
Description
Allows for the creation of an exception class hierarchy. Exception classes inherit from one or more existing classes, ultimately all classes inherit from the Unexpected
exception class
Configuration and Environment
Defines the following attributes;
class
-
Defaults to
Unexpected
. Can be used to differentiate different classes of error. Non default values for this attribute must have been defined with a call to "has_exception" otherwise an exception will be thrown. Oh the irony
Subroutines/Methods
has_exception
Unexpected->has_exception( 'new_classname', [ 'parent1', 'parent2' ] );
Defines a new exception class. Parent classes must already exist. Default parent class is Unexpected
;
instance_of
$bool = $exception_obj->instance_of( 'exception_classname' );
Is the exception object an instance of the exception class
Diagnostics
None
Dependencies
Incompatibilities
There are no known incompatibilities in this module
Bugs and Limitations
There are no known bugs in this module. Please report problems to http://rt.cpan.org/NoAuth/Bugs.html?Dist=Unexpected. Patches are welcome
Acknowledgements
Larry Wall - For the Perl programming language
Author
Peter Flanigan, <pjfl@cpan.org>
License and Copyright
Copyright (c) 2013 Peter Flanigan. All rights reserved
This program 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 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE