1Class::ErrorHandler(3)User Contributed Perl DocumentationClass::ErrorHandler(3)
2
3
4
6 Class::ErrorHandler - Base class for error handling
7
9 package Foo;
10 use base qw( Class::ErrorHandler );
11
12 sub class_method {
13 my $class = shift;
14 ...
15 return $class->error("Help!")
16 unless $continue;
17 }
18
19 sub object_method {
20 my $obj = shift;
21 ...
22 return $obj->error("I am no more")
23 unless $continue;
24 }
25
26 package main;
27 use Foo;
28
29 Foo->class_method or die Foo->errstr;
30
31 my $foo = Foo->new;
32 $foo->object_method or die $foo->errstr;
33
35 Class::ErrorHandler provides an error-handling mechanism that's generic
36 enough to be used as the base class for a variety of OO classes. Sub‐
37 classes inherit its two error-handling methods, error and errstr, to
38 communicate error messages back to the calling program.
39
40 On failure (for whatever reason), a subclass should call error and
41 return to the caller; error itself sets the error message internally,
42 then returns "undef". This has the effect of the method that failed
43 returning "undef" to the caller. The caller should check for errors by
44 checking for a return value of "undef", and calling errstr to get the
45 value of the error message on an error.
46
47 As demonstrated in the SYNOPSIS, error and errstr work as both class
48 methods and object methods.
49
51 Class->error($message)
52
53 $object->error($message)
54
55 Sets the error message for either the class Class or the object $object
56 to the message $message. Returns "undef".
57
58 Class->errstr
59
60 $object->errstr
61
62 Accesses the last error message set in the class Class or the object
63 $object, respectively, and returns that error message.
64
66 Class::ErrorHandler is free software; you may redistribute it and/or
67 modify it under the same terms as Perl itself.
68
70 Except where otherwise noted, Class::ErrorHandler is Copyright 2004
71 Benjamin Trott, cpan@stupidfool.org. All rights reserved.
72
73
74
75perl v5.8.8 2004-08-15 Class::ErrorHandler(3)