1Graph::Error(3) User Contributed Perl Documentation Graph::Error(3)
2
3
4
6 GD::Graph::Error - Error handling for GD::Graph classes
7
9 use GD::Graph::Error_subclass;
10
12 This class is a parent for all GD::Graph classes, including
13 GD::Graph::Data, and offers error and warning handling and some
14 debugging control.
15
16 Errors are stored in a lexical hash in this package, so the
17 implementation of the subclass should be irrelevant.
18
20 These methods can be used by users of any of the subclasses of
21 GD::Graph::Error to get at the errors of objects or classes.
22
23 $object->error() OR Class->error()
24 Returns a list of all the errors that the current object has
25 accumulated. In scalar context, returns the last error. If called as a
26 class method it works at a class level. This is handy when a
27 constructor fails, for example:
28
29 my $data = GD::Graph::Data->new()
30 or die GD::Graph::Data->error;
31 $data->read(file => '/foo/bar.data')
32 or die $data->error;
33
34 or if you really are only interested in the last error:
35
36 $data->read(file => '/foo/bar.data')
37 or die scalar $data->error;
38
39 This implementation does not clear the error list, so if you don't die
40 on errors, you will need to make sure to never ask for anything but the
41 last error (put this in scalar context) or to call "clear_error()" now
42 and again.
43
44 Errors are more verbose about where the errors originated if the
45 $GD::Graph::Error::Debug variable is set to a true value, and even more
46 verbose if this value is larger than 5.
47
48 If $Debug is larger than 3, both of these will always return the full
49 list of errors and warnings (although the meaning of "has_warning" and
50 "has_error" does not change).
51
52 $object->has_error() OR Class->has_error()
53 $object->has_warning() OR Class->has_warning()
54 Returns true if there are pending errors (warnings) for the object (or
55 class). To be more precise, it returns a list of errors in list
56 context, and the number of errors in scalar context.
57
58 This allows you to check for errors and warnings after a large number
59 of operations which each might fail:
60
61 $data->read(file => '/foo/bar.data') or die $data->error;
62 while (my @foo = $sth->fetchrow_array)
63 {
64 $data->add_point(@foo);
65 }
66 $data->set_x(12, 'Foo');
67 $data->has_warning and warn $data->warning;
68 $data->has_error and die $data->error;
69
70 The reason to call this, instead of just calling "error()" or
71 "warning()" and looking at its return value, is that this method is
72 much more efficient and fast.
73
74 If you want to count anything as bad, just set $ErrorLevel to 0, after
75 which you only need to call "has_error".
76
77 $object->clear_errors() or Class->clear_errors()
78 Clears all outstanding errors.
79
81 These methods are only to be called from within this class and its
82 Subclasses.
83
84 $object->_set_error(arg) or Class->_set_error(arg)
85 $object->_set_warning(arg) or Class->_set_warning(arg)
86 Subclasses call this to set an error. The argument can be a reference
87 to an array, of which the first element should be the error level, and
88 the second element the error message. Alternatively, it can just be the
89 message, in which case the error level will be assumed to be
90 $ErrorLevel.
91
92 If the error level is >= $CriticalLevel the program will die, using
93 Carp::croak to display the current message, as well as all the other
94 error messages pending.
95
96 In the current implementation these are almost identical when called
97 with a scalar argument, except that the default error level is
98 different. When called with an array reference, they are identical in
99 function. This may change in the future. They're mainly here for code
100 clarity.
101
102 $object->_move_errors
103 Move errors from an object into the class it belongs to. This can be
104 useful if something nasty happens in the constructor, while
105 instantiating one of these objects, and you need to move these errors
106 into the class space before returning. (see GD::Graph::Data::new for an
107 example)
108
110 $GD::Graph::Error::Debug
111 The higher this value, the more verbose error messages will be. At the
112 moment, any true value will cause the line number and source file of
113 the caller at the top of the stack to be included, a value of more than
114 2 will include the error severity, and a value of more than 5 will also
115 include the direct caller's (i.e. the spot where the error message was
116 generated) line number and package. Default: 0.
117
118 $GD::Graph::Error::ErrorLevel
119 Errors levels below this value will be counted as warnings, and error
120 levels above (and inclusive) up to $CriticalLevel will be counted as
121 errors. This is also the default error level for the "_set_error()"
122 method. This value should be 0 or larger, and smaller than
123 $CriticalLevel. Default: 5.
124
125 $GD::Graph::Error::CriticalLevel
126 Any errorlevel of or above this level will immediately cause the
127 program to die with the specified message, using Carp::croak. Default:
128 10.
129
131 As with all Modules for Perl: Please stick to using the interface. If
132 you try to fiddle too much with knowledge of the internals of this
133 module, you could get burned. I may change them at any time.
134
136 Martien Verbruggen <mgjv@tradingpost.com.au>
137
138 Copyright
139 (c) Martien Verbruggen.
140
141 All rights reserved. This package is free software; you can
142 redistribute it and/or modify it under the same terms as Perl itself.
143
145 GD::Graph, GD::Graph::Data
146
147
148
149perl v5.32.1 2021-01-27 Graph::Error(3)