GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  LOG::REPORT::DISPATCHER::TRY (3)

.ds Aq ’

NAME

Log::Report::Dispatcher::Try - capture all reports as exceptions

CONTENTS

INHERITANCE



 Log::Report::Dispatcher::Try
   is a Log::Report::Dispatcher



SYNOPSIS



 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



DESCRIPTION

The Log::Report::try() catches errors in the block (CODE reference) which is just following the function name. All dispatchers are temporarily disabled by try, and messages which are reported are collected within a temporary dispatcher named try. When the CODE has run, that try dispatcher is returned in $@, and all original dispatchers reinstated.

Then, after the try has finished, the routine which used the try should decide what to do with the collected reports. These reports are collected as Log::Report::Exception objects. They can be ignored, or thrown to a higher level try... causing an exit of the program if there is none.

Extends DESCRIPTION in Log::Report::Dispatcher.

METHODS

Extends METHODS in Log::Report::Dispatcher.

    Constructors

Extends Constructors in Log::Report::Dispatcher.
$obj-><B>closeB>() Only when initiated with a FILENAME, the file will be closed. In any other case, nothing will be done.
Log::Report::Dispatcher::Try-><B>newB>($type, $name, %options)


 -Option       --Defined in             --Default
  accept         Log::Report::Dispatcher  depend on mode
  charset        Log::Report::Dispatcher  <undef>
  died                                    undef
  exceptions                              []
  format_reason  Log::Report::Dispatcher  LOWERCASE
  hide                                    NONE
  locale         Log::Report::Dispatcher  <system locale>
  mode           Log::Report::Dispatcher  NORMAL



accept => REASONS
charset => CHARSET
died => STRING The exit string ($@) of the eval’ed block.
exceptions => ARRAY ARRAY of Log::Report::Exception objects.
format_reason => ’UPPERCASE’|’LOWERCASE’|’UCFIRST’|’IGNORE’|CODE
hide => REASON|ARRAY|’ALL’|’NONE [1.09] see hide()
locale => LOCALE
mode => ’NORMAL’|’VERBOSE’|’ASSERT’|’DEBUG’|0..3

    Accessors

Extends Accessors in Log::Report::Dispatcher.
$obj-><B>diedB>( [STRING] ) The message which was reported by eval, which is used internally to catch problems in the try block.
$obj-><B>exceptionsB>() Returns all collected Log::Report::Exceptions. The last of them may be a fatal one. The other are non-fatal.
$obj-><B>hideB>(REASON|REASONS|ARRAY|’ALL’|’NONE’) [1.09] By default, the try will only catch messages which stop the execution of the block (errors etc, internally a ’die’). Other messages are passed to parent try blocks, if none than to the dispatchers.

This option gives the opportunity to block, for instance, trace messages. Those messages are still collected inside the try object, so may get passed-on later via reportAll() if you like.

Be warned: Using this method will reset the whole ’hide’ configuration: it’s a set not an add.

example: change the setting of the running block



  my $parent_try = dispatcher active-try;
  parent_try->hide(NONE);



$obj-><B>hidesB>(REASON)
$obj-><B>isDisabledB>() Inherited, see Accessors in Log::Report::Dispatcher
$obj-><B>modeB>() Inherited, see Accessors in Log::Report::Dispatcher
$obj-><B>nameB>() Inherited, see Accessors in Log::Report::Dispatcher
$obj-><B>needsB>( [$reason] ) Inherited, see Accessors in Log::Report::Dispatcher
$obj-><B>typeB>() Inherited, see Accessors in Log::Report::Dispatcher

    Logging

Extends Logging in Log::Report::Dispatcher.
$obj-><B>addSkipStackB>(@CODE)
Log::Report::Dispatcher::Try-><B>addSkipStackB>(@CODE) Inherited, see Logging in Log::Report::Dispatcher
$obj-><B>collectLocationB>()
Log::Report::Dispatcher::Try-><B>collectLocationB>() Inherited, see Logging in Log::Report::Dispatcher
$obj-><B>collectStackB>( [$maxdepth] )
Log::Report::Dispatcher::Try-><B>collectStackB>( [$maxdepth] ) Inherited, see Logging in Log::Report::Dispatcher
$obj-><B>logB>($opts, $reason, $message) Other dispatchers translate the message here, and make it leave the program. However, messages in a try block are only captured in an intermediate layer: they may never be presented to an end-users. And for sure, we do not know the language yet.

The $message is either a STRING or a Log::Report::Message.

$obj-><B>reportAllB>(%options) Re-cast the messages in all collect exceptions into the defined dispatchers, which were disabled during the try block. The %options will end-up as HASH of %options to Log::Report::report(); see Log::Report::Exception::throw() which does the job.
$obj-><B>reportFatalB>() Re-cast only the fatal message to the defined dispatchers. If the block was left without problems, then nothing will be done. The %options will end-up as HASH of %options to Log::Report::report(); see Log::Report::Exception::throw() which does the job.
$obj-><B>skipStackB>() Inherited, see Logging in Log::Report::Dispatcher
$obj-><B>stackTraceLineB>(%options)
Log::Report::Dispatcher::Try-><B>stackTraceLineB>(%options) Inherited, see Logging in Log::Report::Dispatcher
$obj-><B>translateB>(HASH-$of-%options, $reason, $message) Inherited, see Logging in Log::Report::Dispatcher

    Status

$obj-><B>failedB>() Returns true if the block was left with an fatal message.
$obj-><B>showStatusB>() If this object is kept in $@, and someone uses this as string, we want to show the fatal error message.

The message is not very informative for the good cause: we do not want people to simply print the $@, but wish for a re-cast of the message using reportAll() or reportFatal().

$obj-><B>successB>() Returns true if the block exited normally.
$obj-><B>wasFatalB>(%options) Returns the Log::Report::Exception which caused the try block to die, otherwise an empty LIST (undef).



 -Option--Default
  class   undef



class => CLASS|REGEX Only return the exception if it was fatal, and in the same time in the specified CLASS (as string) or matches the REGEX. See Log::Report::Message::inClass()

DETAILS

Extends DETAILS in Log::Report::Dispatcher.

OVERLOADING

overload: <B>booleanB> Returns true if the previous try block did produce a terminal error. This try object is assigned to $@, and the usual perl syntax is if($@) {...error-handler...}.
overload: <B>stringifyB> When $@ is used the traditional way, it is checked to have a string content. In this case, stringify into the fatal error or nothing.

SEE ALSO

This module is part of Log-Report distribution version 1.13, built on February 03, 2016. Website: http://perl.overmeer.net/log-report/

LICENSE

Copyrights 2007-2016 by [Mark Overmeer]. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 LOG::REPORT::DISPATCHER::TRY (3) 2016-02-03

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.