1Log::Report::Exception(U3s)er Contributed Perl DocumentatLioogn::Report::Exception(3)
2
3
4
6 Log::Report::Exception - a collected report
7
9 # created within a try block
10 try { error "help!" };
11 my $exception = $@->wasFatal;
12 $exception->throw if $exception;
13
14 $@->reportFatal; # combination of above two lines
15
16 my $message = $exception->message; # the Log::Report::Message
17
18 if($message->inClass('die')) ...
19 if($exception->inClass('die')) ... # same
20 if($@->wasFatal(class => 'die')) ... # same
21
23 In Log::Report, exceptions are not as extended as available in
24 languages as Java: you do not create classes for them. The only thing
25 an exception object does, is capture some information about an
26 (untranslated) report.
27
29 Constructors
30 Log::Report::Exception->new(%options)
31 -Option --Default
32 message <required>
33 reason <required>
34 report_opts {}
35
36 message => Log::Report::Message
37 reason => REASON
38 report_opts => HASH
39
40 Accessors
41 $obj->isFatal()
42 Returns whether this exception has a severity which makes it fatal
43 when thrown. [1.34] This can have been overruled with the
44 "is_fatal" attribute. See Log::Report::Util::is_fatal().
45
46 example:
47
48 if($ex->isFatal) { $ex->throw(reason => 'ALERT') }
49 else { $ex->throw }
50
51 $obj->message( [$message] )
52 Change the $message of the exception, must be a
53 Log::Report::Message object.
54
55 When you use a "Log::Report::Message" object, you will get a new
56 one returned. Therefore, if you want to modify the message in an
57 exception, you have to re-assign the result of the modification.
58
59 example:
60
61 $e->message->concat('!!')); # will not work!
62 $e->message($e->message->concat('!!'));
63 $e->message(__x"some message {msg}", msg => $xyz);
64
65 $obj->reason( [$reason] )
66 $obj->report_opts()
67
68 Processing
69 $obj->inClass($class|Regexp)
70 Check whether any of the classes listed in the message match $class
71 (string) or the Regexp. This uses Log::Report::Message::inClass().
72
73 $obj->print( [$fh] )
74 The default filehandle is STDOUT.
75
76 example:
77
78 print $exception; # via overloading
79 $exception->print; # OO style
80
81 $obj->throw(%options)
82 Insert the message contained in the exception into the currently
83 defined dispatchers. The "throw" name is commonly known exception
84 related terminology for "report".
85
86 The %options overrule the captured options to
87 Log::Report::report(). This can be used to overrule a destination.
88 Also, the reason can be changed.
89
90 example: overrule defaults to report
91
92 try { print {to => 'stderr'}, ERROR => 'oops!' };
93 $@->reportFatal(to => 'syslog');
94
95 $exception->throw(to => 'syslog');
96
97 $@->wasFatal->throw(reason => 'WARNING');
98
99 $obj->toHTML( [$locale] )
100 [1.11] as toString(), and escape HTML volatile characters.
101
102 $obj->toString( [$locale] )
103 Prints the reason and the message. Differently from throw(), this
104 only represents the textual content: it does not re-cast the
105 exceptions to higher levels.
106
107 example: printing exceptions
108
109 print $_->toString for $@->exceptions;
110 print $_ for $@->exceptions; # via overloading
111
113 overload: stringification
114 Produces "reason: message".
115
117 This module is part of Log-Report distribution version 1.34, built on
118 September 15, 2022. Website: http://perl.overmeer.net/CPAN/
119
121 Copyrights 2007-2022 by [Mark Overmeer <markov@cpan.org>]. For other
122 contributors see ChangeLog.
123
124 This program is free software; you can redistribute it and/or modify it
125 under the same terms as Perl itself. See http://dev.perl.org/licenses/
126
127
128
129perl v5.36.0 2022-09-15 Log::Report::Exception(3)