Log::Report::Exception3pm
A single generated event
Usage
# created within a try blocktry { error "help!" };my $exception = $@->wasFatal;$exception->throw if $exception;$@->reportFatal; # combination of above two linesmy $message = $exception->message; # the Log::Report::Messageif($message->taggedWith('die')) ...if($exception->taggedWith('die')) ... # sameif($@->wasFatal(tag => 'die')) ... # same
Overview
In Log::Report, exceptions are not as extended as available in languages as Java: you do not create classes for them. The only thing an exception object does, is capture some information about an (untranslated) report.
Overloaded
overload: "" stringification
|
Produces "reason: message" via |
|---|---|
overload:
|
Always returns |
Methods
Constructors
- $class->
new(%options) -
Create a new exception object, which is basically a
"message"which was produced for a"reason".-Option --Defaultmessage <required>reason <required>report_opts +{ }- message => Log::Report::Message
- reason => $reason
- report_opts => \%opts
Attributes
- $obj->
isFatal() -
Returns whether this exception has a severity which makes it fatal when thrown. [1.34] This can have been overruled with the
"is_fatal"attribute. SeeLog::Report::Util::is_fatal().» example:
if($ex->isFatal) { $ex->throw(reason => 'ALERT') }else { $ex->throw }
- $obj->
message( [$message] ) -
Change the
$messageof the exception, must be a Log::Report::Message object.When you use a
"Log::Report::Message"object, you will get a new one returned. Therefore, if you want to modify the message in an exception, you have to re-assign the result of the modification.» example:
$e->message->concat('!!')); # will not work!$e->message($e->message->concat('!!'));$e->message(__x"some message {xyz}", xyz => $xyz);
- $obj->
reason( [$reason] )
- $obj->
report_opts()
Processing
- $obj->
inClass($tag|Regexp) -
Deprecated name for
taggedWith().
- $obj->
print( [$fh] ) -
The default filehandle is STDOUT.
» example:
print $exception; # via overloading$exception->print; # OO style
- $obj->
taggedWith($tag|Regexp) -
[1.44] Check whether any of the classes listed in the message match
$tag(string) or the Regexp. This usesLog::Report::Message::taggedWith().
- $obj->
throw(%options) -
Insert the message contained in the exception into the currently defined dispatchers. The
"throw"as method name is commonly known exception related terminology for"report".The
%optionsoverrule the captured options toLog::Report::report(). This can be used to overrule a destination. Also, the reason can be changed.Returned is the LIST of dispatchers which have accepted the forwarded exception.
» example: overrule defaults to report
try { report {to => 'default'}, ERROR => 'oops!' };$@->reportFatal(to => 'syslog');my ($syslog) = $exception->throw(to => 'syslog');my @disps = $@->wasFatal->throw(reason => 'WARNING');
- $obj->
toHTML( [$locale] ) -
[1.11] Calls
toString()and then escapes HTML volatile characters.
- $obj->
toString( [$locale] ) -
Prints the reason and the message. Differently from
throw(), this only represents the textual content: it does not re-cast the exceptions to higher levels.» example: printing exceptions
print $_->toString for $@->exceptions;print $_ for $@->exceptions; # via overloading
Diagnostics
- Error:
message()of exception expects Log::Report::Message, got $what. -
Cast by
message()
Releases
8 releases since Debian 7 (Wheezy); the text changed 7 times.