3
use base qw( OpenSRF Error );
4
use OpenSRF::Utils::Logger;
6
my $log = "OpenSRF::Utils::Logger";
10
my( $class, $message ) = @_;
11
$class = ref( $class ) || $class;
13
$self->{'msg'} = ${$class . '::ex_msg_header'} ." \n$message";
14
return bless( $self, $class );
17
sub message() { return $_[0]->{'msg'}; }
24
Top level exception. This class logs an exception when it is thrown. Exception subclasses
25
should subclass one of OpenSRF::EX::INFO, NOTICE, WARN, ERROR, CRITICAL, and PANIC and provide
26
a new() method that takes a message and a message() method that returns that message.
33
throw OpenSRF::EX::Jabber ("I Am Dying");
35
OpenSRF::EX::InvalidArg->throw( "Another way" );
37
my $je = OpenSRF::EX::Jabber->new( "I Cannot Connect" );
41
See OpenSRF/EX.pm for example subclasses.
45
# Log myself and throw myself
47
#sub message() { shift->alert_abstract(); }
49
#sub new() { shift->alert_abstract(); }
55
if( ! ref( $self ) || scalar( @_ ) ) {
56
$self = $self->new( @_ );
59
if( $self->class->isa( "OpenSRF::EX::INFO" ) ||
60
$self->class->isa( "OpenSRF::EX::NOTICE" ) ||
61
$self->class->isa( "OpenSRF::EX::WARN" ) ) {
63
$log->debug( $self->stringify(), $log->DEBUG );
66
else{ $log->debug( $self->stringify(), $log->ERROR ); }
75
my $ctime = localtime();
76
my( $package, $file, $line) = get_caller();
77
my $name = ref( $self );
78
my $msg = $self->message();
80
$msg =~ s/^/Mess: /mg;
82
return " * ! EXCEPTION ! * \nTYPE: $name\n$msg\n".
83
"Loc.: $line $package \nLoc.: $file \nTime: $ctime\n";
87
# --- determine the originating caller of this exception
92
while( $package->isa( "Error" ) || $package =~ /^Error::/ ) {
93
$package = caller( ++$x );
101
# -------------------------------------------------------------------
102
# -------------------------------------------------------------------
104
# Top level exception subclasses defining the different exception
107
# -------------------------------------------------------------------
109
package OpenSRF::EX::INFO;
110
use base qw(OpenSRF::EX);
111
our $ex_msg_header = "System INFO";
113
# -------------------------------------------------------------------
115
package OpenSRF::EX::NOTICE;
116
use base qw(OpenSRF::EX);
117
our $ex_msg_header = "System NOTICE";
119
# -------------------------------------------------------------------
121
package OpenSRF::EX::WARN;
122
use base qw(OpenSRF::EX);
123
our $ex_msg_header = "System WARNING";
125
# -------------------------------------------------------------------
127
package OpenSRF::EX::ERROR;
128
use base qw(OpenSRF::EX);
129
our $ex_msg_header = "System ERROR";
131
# -------------------------------------------------------------------
133
package OpenSRF::EX::CRITICAL;
134
use base qw(OpenSRF::EX);
135
our $ex_msg_header = "System CRITICAL";
137
# -------------------------------------------------------------------
139
package OpenSRF::EX::PANIC;
140
use base qw(OpenSRF::EX);
141
our $ex_msg_header = "System PANIC";
143
# -------------------------------------------------------------------
144
# -------------------------------------------------------------------
146
# Some basic exceptions
148
# -------------------------------------------------------------------
149
package OpenSRF::EX::Jabber;
150
use base 'OpenSRF::EX::ERROR';
151
our $ex_msg_header = "Jabber Exception";
153
package OpenSRF::EX::JabberDisconnected;
154
use base 'OpenSRF::EX::ERROR';
155
our $ex_msg_header = "JabberDisconnected Exception";
157
=head2 OpenSRF::EX::Jabber
159
Thrown when there is a problem using the Jabber service
163
package OpenSRF::EX::Transport;
164
use base 'OpenSRF::EX::ERROR';
165
our $ex_msg_header = "Transport Exception";
169
# -------------------------------------------------------------------
170
package OpenSRF::EX::InvalidArg;
171
use base 'OpenSRF::EX::ERROR';
172
our $ex_msg_header = "Invalid Arg Exception";
174
=head2 OpenSRF::EX::InvalidArg
176
Thrown where an argument to a method was invalid or not provided
181
# -------------------------------------------------------------------
182
package OpenSRF::EX::NotADomainObject;
183
use base 'OpenSRF::EX::ERROR';
184
our $ex_msg_header = "Must be a Domain Object";
186
=head2 OpenSRF::EX::NotADomainObject
188
Thrown where a OpenSRF::DomainObject::oilsScalar or
189
OpenSRF::DomainObject::oilsPair was passed a value that
190
is not a perl scalar or a OpenSRF::DomainObject.
195
# -------------------------------------------------------------------
196
package OpenSRF::EX::ArrayOutOfBounds;
197
use base 'OpenSRF::EX::ERROR';
198
our $ex_msg_header = "Tied array access on a nonexistant index";
200
=head2 OpenSRF::EX::ArrayOutOfBounds
202
Thrown where a TIEd array (OpenSRF::DomainObject::oilsArray) was accessed at
209
# -------------------------------------------------------------------
210
package OpenSRF::EX::Socket;
211
use base 'OpenSRF::EX::ERROR';
212
our $ex_msg_header = "Socket Exception";
214
=head2 OpenSRF::EX::Socket
216
Thrown when there is a network layer exception
222
# -------------------------------------------------------------------
223
package OpenSRF::EX::Config;
224
use base 'OpenSRF::EX::PANIC';
225
our $ex_msg_header = "Config Exception";
227
=head2 OpenSRF::EX::Config
229
Thrown when a package requires a config option that it cannot retrieve
230
or the config file itself cannot be loaded
235
# -------------------------------------------------------------------
236
package OpenSRF::EX::User;
237
use base 'OpenSRF::EX::ERROR';
238
our $ex_msg_header = "User Exception";
240
=head2 OpenSRF::EX::User
242
Thrown when an error occurs due to user identification information
246
package OpenSRF::EX::Session;
247
use base 'OpenSRF::EX::ERROR';
248
our $ex_msg_header = "Session Error";