Exception-Base
view release on metacpan or search on metacpan
package My::Package;
use Exception::Base;
Exception::Base->throw( ignore_class => "My::Base" );
This setting can be changed with import interface.
use Exception::Base ignore_class => "My::Base";
- ignore\_level (rw)
Contains the number of level on stack trace to ignore. It is useful if some
package throws an exception but this module shouldn't be listed in stack
trace. It can be used with or without _ignore\_package_ attribute.
# Convert warning into exception. The signal handler ignores itself.
use Exception::Base 'Exception::My::Warning';
$SIG{__WARN__} = sub {
Exception::My::Warning->throw( message => $_[0], ignore_level => 1 );
};
- time (ro)
Contains the timestamp of the thrown exception. Collected if the verbosity on
throwing exception was greater than 1.
eval { Exception::Base->throw( message=>"Message" ); };
print scalar localtime $@->time;
- pid (ro)
Contains the PID of the Perl process at time of thrown exception. Collected
if the verbosity on throwing exception was greater than 1.
eval { Exception::Base->throw( message=>"Message" ); };
kill 10, $@->pid;
- tid (ro)
Contains the tid of the thread or undef if threads are not used. Collected
if the verbosity on throwing exception was greater than 1.
- uid (ro)
- euid (ro)
- gid (ro)
- egid (ro)
Contains the real and effective uid and gid of the Perl process at time of
thrown exception. Collected if the verbosity on throwing exception was
greater than 1.
- caller\_stack (ro)
Contains the error stack as array of array with information about caller
functions. The first 8 elements of the array's row are the same as first 8
elements of the output of `caller` function. Further elements are optional
and are the arguments of called function. Collected if the verbosity on
throwing exception was greater than 1. Contains only the first element of
caller stack if the verbosity was lower than 3.
If the arguments of called function are references and
`[Scalar::Util](https://metacpan.org/pod/Scalar::Util)::weaken` function is available then reference is weakened.
eval { Exception::Base->throw( message=>"Message" ); };
($package, $filename, $line, $subroutine, $hasargs, $wantarray,
$evaltext, $is_require, @args) = $@->caller_stack->[0];
- propagated\_stack (ro)
Contains the array of array which is used for generating "...propagated at"
message. The elements of the array's row are the same as first 3 elements of
the output of `caller` function.
- max\_arg\_len (rw, default: 64)
Contains the maximal length of argument for functions in backtrace output.
Zero means no limit for length.
sub a { Exception::Base->throw( max_arg_len=>5 ) }
a("123456789");
- max\_arg\_nums (rw, default: 8)
Contains the maximal number of arguments for functions in backtrace output.
Zero means no limit for arguments.
sub a { Exception::Base->throw( max_arg_nums=>1 ) }
a(1,2,3);
- max\_eval\_len (rw, default: 0)
Contains the maximal length of eval strings in backtrace output. Zero means
no limit for length.
eval "Exception->throw( max_eval_len=>10 )";
print "$@";
- defaults
Meta-attribute contains the list of default values.
my $e = Exception::Base->new;
print defined $e->{verbosity}
? $e->{verbosity}
: $e->{defaults}->{verbosity};
- default\_attribute (default: 'message')
Meta-attribute contains the name of the default attribute. This attribute
will be set for one argument throw method. This attribute has meaning for
derived classes.
use Exception::Base 'Exception::My' => {
has => 'myattr',
default_attribute => 'myattr',
};
eval { Exception::My->throw("string") };
print $@->myattr; # "string"
- numeric\_attribute (default: 'value')
( run in 1.145 second using v1.01-cache-2.11-cpan-39bf76dae61 )