File: Exception.pod

package info (click to toggle)
liblog-report-perl 1.41-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 572 kB
  • sloc: perl: 2,819; makefile: 8
file content (181 lines) | stat: -rw-r--r-- 4,367 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
=encoding utf8

=head1 NAME

Log::Report::Exception - a single generated event

=head1 SYNOPSIS

  # created within a try block
  try { error "help!" };
  my $exception = $@->wasFatal;
  $exception->throw if $exception;

  $@->reportFatal;  # combination of above two lines

  my $message = $exception->message;   # the Log::Report::Message

  if($message->inClass('die')) ...
  if($exception->inClass('die')) ...   # same
  if($@->wasFatal(class => 'die')) ... # same

=head1 DESCRIPTION

In L<Log::Report|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.

=head1 OVERLOADED

=over 4

=item overload: B<""> stringification

Produces "reason: message" via L<toString()|Log::Report::Exception/"Processing">.

=item overload: B<bool> boolean condition

Always returns C<true>: the exception object exists.

=back

=head1 METHODS

=head2 Constructors

=over 4

=item $class-E<gt>B<new>(%options)

Create a new exception object, which is basically a C<message> which
was produced for a C<reason>.

 -Option     --Default
  message      <required>
  reason       <required>
  report_opts  +{ }

=over 2

=item message => Log::Report::Message

=item reason => $reason

=item report_opts => \%opts

=back

=back

=head2 Accessors

=over 4

=item $obj-E<gt>B<isFatal>()

Returns whether this exception has a severity which makes it fatal
when thrown. [1.34] This can have been overruled with the C<is_fatal>
attribute.  See L<Log::Report::Util::is_fatal()|Log::Report::Util/"Reasons">.

example: 

  if($ex->isFatal) { $ex->throw(reason => 'ALERT') }
  else { $ex->throw }

=item $obj-E<gt>B<message>( [$message] )

Change the C<$message> of the exception, must be a L<Log::Report::Message|Log::Report::Message>
object.

When you use a C<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);

=item $obj-E<gt>B<reason>( [$reason] )

Z<>

=item $obj-E<gt>B<report_opts>()

Z<>

=back

=head2 Processing

=over 4

=item $obj-E<gt>B<inClass>($class|Regexp)

Check whether any of the classes listed in the message match C<$class>
(string) or the Regexp.  This uses L<Log::Report::Message::inClass()|Log::Report::Message/"Processing">.

=item $obj-E<gt>B<print>( [$fh] )

The default filehandle is STDOUT.

example: 

  print $exception;  # via overloading
  $exception->print; # OO style

=item $obj-E<gt>B<throw>(%options)

Insert the message contained in the exception into the currently defined
dispatchers.  The C<throw> as method name is commonly known exception
related terminology for C<report>.

The C<%options> overrule the captured options to L<Log::Report::report()|Log::Report/"Report Production and Configuration">.
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');

=item $obj-E<gt>B<toHTML>( [$locale] )

[1.11] Calls L<toString()|Log::Report::Exception/"Processing"> and then escapes HTML volatile characters.

=item $obj-E<gt>B<toString>( [$locale] )

Prints the reason and the message.  Differently from L<throw()|Log::Report::Exception/"Processing">, 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

=back

=head1 SEE ALSO

This module is part of Log-Report version 1.41,
built on September 11, 2025. Website: F<http://perl.overmeer.net/CPAN/>

=head1 LICENSE

For contributors see file ChangeLog.

This software is copyright (c) 2007-2025 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.