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::Socket;
183 use base 'OpenSRF::EX::ERROR';
184 our $ex_msg_header = "Socket Exception";
186 =head2 OpenSRF::EX::Socket
188 Thrown when there is a network layer exception
194 # -------------------------------------------------------------------
195 package OpenSRF::EX::Config;
196 use base 'OpenSRF::EX::PANIC';
197 our $ex_msg_header = "Config Exception";
199 =head2 OpenSRF::EX::Config
201 Thrown when a package requires a config option that it cannot retrieve
202 or the config file itself cannot be loaded
207 # -------------------------------------------------------------------
208 package OpenSRF::EX::User;
209 use base 'OpenSRF::EX::ERROR';
210 our $ex_msg_header = "User Exception";
212 =head2 OpenSRF::EX::User
214 Thrown when an error occurs due to user identification information
218 package OpenSRF::EX::Session;
219 use base 'OpenSRF::EX::ERROR';
220 our $ex_msg_header = "Session Error";