Log::R...r::Try(3pm)
π NAME π
Log::Report::Dispatcher::Try β the dispatcher that catches, like, ALL the reports and turns them into exceptions. Bestie it's a giant safety net under your code. π₯
β¨
π¦ INHERITANCE π¦
Log::Report::Dispatcher::Try
is a Log::Report::Dispatcher
so yeah, it inherits everything from Log::Report::Dispatcher, no cap π
β¨ SYNOPSIS β¨
okay so here's how we do it, read every line because every line is doing something:
try { ... }; # mind the ';' !!
if($@) { # signals something went wrong
if(try {...}) { # block ended normally
my $x = try { read_temperature() };
my @x = try { read_lines_from_file() };
try { ... } # no comma!!
mode => 'DEBUG', accept => 'ERROR-';
try sub { ... }, # with comma
mode => 'DEBUG', accept => 'ALL';
try \&myhandler, accept => 'ERROR-';
try { ... } hide => 'TRACE';
print ref $@; # Log::Report::Dispatcher::Try
$@->reportFatal; # re-dispatch result of try block
$@->reportAll; # ... also warnings etc
if($@) {...} # if errors
if($@->failed) { # same # }
if($@->success) { # no errors # }
try { # something causes an error report, which is caught
failure 'no network';
};
$@->reportFatal(to => 'syslog'); # overrule destination
print $@->exceptions; # no re-cast, just print
ngl the comments in there are load-bearing. read them. π
πΈ DESCRIPTION πΈ
try does what Perl's built-in eval() does but like... actually correct. It gives you real exception handling, which Perl core was frankly not serving. π
The Log::Report::try() function makes this ::Try dispatcher object, and its name is 'try' β¨. Once the try() is over, the object is sitting right there in $@. And that $@ as a ::Try object behaves exactly like the $@ that eval produced β it just has a million extra features. main character energy fr fr π
The try() function catches fatal errors that happen inside the BLOCK (the CODE reference that just follows the function name) and shoves them into the ::Try object $@. Those errors are not automatically passed on to active dispatchers. BUT β and this is the plot twist β non-fatal exceptions (like info or notice) also get collected (unless they aren't accepted, check new(accept)), and those do immediately get passed to the active dispatchers (unless the reason is hidden, check new(hide)).
After the try() has run, you get to snoop through the collected exceptions. Typically you use wasFatal() to grab the exception that ended the BLOCK's run. π΅οΈβοΈ
Extends "DESCRIPTION" in Log::Report::Dispatcher.
π OVERLOADED π
- overload:
""stringify β when$@is used the old-school way, it gets checked for string content. In that case it stringifies into the fatal error, or nothing at all. π - overload:
boolboolean β returns"true"if the previous try block produced a terminal error. This"try"object is what's sitting in$@, and the usual perl syntax isif($@) {...error-handler...}. So yes, the check you already know just works. slay.
π METHODS π
Extends "METHODS" in Log::Report::Dispatcher.
π Constructors π
Extends "Constructors" in Log::Report::Dispatcher.
$class->new($type, $name, %options)
Inherited, see "Constructors" in Log::Report::Dispatcher.
here's the option menu, defaults included, don't skip any:
acceptβ defined inLog::Report::Dispatcher, default depend on modecharsetβ defined inLog::Report::Dispatcher, defaultundefdiedβ defaultundefexceptionsβ default[]format_reasonβ defined inLog::Report::Dispatcher, default'LOWERCASE'hideβ default'NONE'localeβ defined inLog::Report::Dispatcher, default<system locale>modeβ defined inLog::Report::Dispatcher, default'NORMAL'on_dieβ default'ERROR'
and now the deets on each one:
accept => $reasons|\@reasonsβ the reasons you're willing to accept, one or a list.charset => CHARSETβ the charset, you know the vibe.died => $textβ the exit string or object ($@) of the eval'ed block, in its unprocessed state. Raw. Untouched. π«£exceptions => \@objectsβ an ARRAY ofLog::Report::Exceptionobjects.format_reason => 'UPPERCASE'|'LOWERCASE'|'UCFIRST'|'IGNORE'|CODEβ pick your formatting era.hide => $reasons|\@reasons|'ALL'|'NONE'β[1.09]seehide()locale => LOCALEβ the locale.mode => 'NORMAL'|'VERBOSE'|'ASSERT'|'DEBUG'|0..3β mode selection, numbers work too.on_die => 'ERROR'|'PANIC'β when code running in this block exits with adie(), it gets translated into aLog::Report::ExceptionusingLog::Report::Die::die_decode(). So the question is: how serious are we about these errors? pick your level of drama. π
π Attributes π
Extends "Attributes" in Log::Report::Dispatcher.
$obj->die2reason()β returns the value ofnew(on_die).$obj->died( [$text] )β the exit$textor object ($@) of the eval'ed block, in its unprocessed state. These will always return"true"when they were deadly, and it always stringifies into something useful. reliable queen β¨$obj->exceptions()β returns all the collectedLog::Report::Exceptionobjects. The last one may be a fatal one. The others are non-fatal. the last one is the dramatic one π$obj->hide(@reasons)β[1.09]by default the try only catches messages that stop the execution of the block (errors and such, internally a'die'). Other messages get passed up to the parent dispatchers.
This option lets you stop, say, trace messages. Those messages are still collected inside the try object (unless excluded by new(accept)), so they may get passed on later via reportAll() if you feel like it. π
β οΈ Be warned bestie: using this method will reset the whole 'hide' configuration. It's a set, not an add. so don't be surprised.
Β» example: change the setting of the running block
my $parent_try = dispatcher 'active-try';
$parent_try->hide('ALL');
$obj->hides($reason)β checks whether the try stops messages that were produced for$reason.$obj->isDisabled()β inherited, see"Attributes" in Log::Report::Dispatcher.$obj->mode()β inherited, see"Attributes" in Log::Report::Dispatcher.$obj->name()β inherited, see"Attributes" in Log::Report::Dispatcher.$obj->needs( [$reason] )β inherited, see"Attributes" in Log::Report::Dispatcher.$obj->type()β inherited, see"Attributes" in Log::Report::Dispatcher.
π Logging π
Extends "Logging" in Log::Report::Dispatcher.
$any->addSkipStack(@CODE)β inherited, see"Logging" in Log::Report::Dispatcher$obj->close()β inherited, see"Logging" in Log::Report::Dispatcher$any->collectLocation()β inherited, see"Logging" in Log::Report::Dispatcher$any->collectStack( [$maxdepth] )β inherited, see"Logging" in Log::Report::Dispatcher$obj->log($opts, $reason, $message)β other dispatchers translate the message right here and let it leave the program. But messages inside a"try"block only get captured in an intermediate layer: they may never be presented to an end-user. And for sure, we do not know the language yet. The$messageis either a STRING or aLog::Report::Message. Improves base, see"Logging" in Log::Report::Dispatcher.$obj->reportAll(%options)β re-casts the messages in all the collected exceptions into the defined dispatchers, which were disabled during the try block. The%optionsend up as a HASH of%optionstoLog::Report::report(); seeLog::Report::Exception::throw()which does the job.$obj->reportFatal(%options)β re-casts only the fatal message to the defined dispatchers. If the block was left without problems, nothing happens. The%optionsend up as a HASH of%optionstoLog::Report::report(); seeLog::Report::Exception::throw()which does the job.$obj->skipStack()β inherited, see"Logging" in Log::Report::Dispatcher$any->stackTraceLine(%options)β inherited, see"Logging" in Log::Report::Dispatcher$obj->translate(\%options, $reason, $message)β inherited, see"Logging" in Log::Report::Dispatcher
β Status β
$obj->failed()β returns"true"if the block was left with a fatal message.$obj->showStatus()β if this object is kept in$@and someone uses it as a string, we want to show the fatal error message.
The message is not very informative, and that's on purpose: we do not want people to just print the $@. we want you to re-cast the message using reportAll() or reportFatal(). do it properly bestie π«Ά
$obj->success()β returns"true"if the block exited normally. celebration time π$obj->wasFatal(%options)β returns theLog::Report::Exceptionwhich caused the"try"block to die, otherwise an empty LIST ("undef").
options:
classβ defaultundeftagβ defaultundef
and the details:
class => $class|REGEXβ deprecated alternative for"tag". (old era, retired era β)tag => $tag|REGEXβ[1.44]only return the exception if it was fatal, and at the same time in the specified$tag(as string) or matches the REGEX. SeeLog::Report::Message::taggedWith().
π₯ DETAILS π₯
Extends "DETAILS" in Log::Report::Dispatcher.
π§ SEE ALSO π§
This module is part of Log-Report version 1.46, built on June 16, 2026. Website: http://perl.overmeer.net/CPAN/
π LICENSE π
For contributors see file ChangeLog.
This software is copyright (c) 2007-2026 by Mark Overmeer.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
okay that's the whole page bestie, go forth and try responsibly β¨π this was Log::R...r::Try(3pm) from User Contributed Perl Documentation, shipped as part of perl v5.40.1 and dated 2026-07-05. ty for reading, ily, bye ππ
π¦ where this page comes from
- ubuntu stonking: liblog-report-perl 1.46-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms