Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Core::GenericException Class Reference

This is basic class of all exceptions and errors. More...

#include <GenericException.h>

Inheritance diagram for Core::GenericException:

Inheritance graph
[legend]
Collaboration diagram for Core::GenericException:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 GenericException (String *message=nil, String *selector=nil, Object *param=nil)
virtual ~GenericException (void)
virtual StringclassName (void) const
 Answer receiver class name.
virtual Stringdescription (void)
virtual StringnotifierString (void) abstract
virtual const Objectoriginator (void)
virtual void originator (const Object *object)
virtual Objectparameter (void)
virtual void selector (String *sel)
virtual void selector (const char *sel)
virtual Stringselector (void)
virtual void printStackOn (Stream *stream)
virtual void pass (void)
 Passes (propagates) the exception thru the rest of stack.
virtual void raiseFrom (const Object *origin)
virtual void raise (void)
 Raises (throws) the receiver as an exception.
virtual void visitBy (Visitor *visitor)

Static Public Member Functions

static GenericExceptionlastException (void)

Protected Member Functions

virtual void getExecutionStack (void)
virtual void privRaise (void) abstract
 This method really throws the receiver as an exception.

Protected Attributes

StringmessageText
String_selector
const Object_originator
Object_parameter

Static Protected Attributes

static GenericExceptionlast_exception = nil

Private Attributes

void * method_stack [MAXSTACKSIZE]
int stack_size

Detailed Description

This is basic class of all exceptions and errors.

It provides some features that may ease debugging.

Definition at line 39 of file GenericException.h.


Constructor & Destructor Documentation

GenericException::GenericException String message = nil,
String selector = nil,
Object param = nil
 

Definition at line 38 of file GenericException.cc.

References _originator, _parameter, _selector, messageText, nil, and stack_size.

00040 {
00041     messageText = message;
00042     _selector   = selector;
00043     _parameter  = param;
00044     _originator = nil;
00045     stack_size = 0;
00046 }

GenericException::~GenericException void   )  [virtual]
 

Definition at line 48 of file GenericException.cc.

00049 {
00050 }


Member Function Documentation

String * GenericException::className void   )  const [virtual]
 

Answer receiver class name.

Because there isn't any standard way to obtain class name this method comes to place.

Every class should rewrite this method but many didn't (yet).

Reimplemented from Core::Object.

Reimplemented in Core::Error, External::ExternalObjectNotFoundError, External::LibraryNotFoundError, Core::FileOpenFailed, Core::IncompleteNextCountError, Core::KeyNotFoundError, Core::NotFoundError, Core::OSError, Core::PositionOutOfBoundsError, Core::SubscriptOutOfBoundsError, Tools::CommandLineMissingArgument, Tools::CommandLineParserError, Tools::CommandLineUnknownArgument, Tools::CommandLineUnsufficientParameters, and Core::ValueNotFoundError.

Definition at line 53 of file GenericException.cc.

00054 {
00055     return new String("GenericException");
00056 }

String * GenericException::description void   )  [virtual]
 

Definition at line 64 of file GenericException.cc.

References messageText, and notifierString().

00065 {
00066     if (messageText == NULL)
00067         return notifierString();
00068     return messageText;
00069 }

void GenericException::getExecutionStack void   )  [protected, virtual]
 

Definition at line 162 of file GenericException.cc.

References last_exception, MAXSTACKSIZE, method_stack, and stack_size.

Referenced by raise().

00163 {
00164 //    if (last_exception == nil)
00165 //      GC_exclude_static_roots(method_stack, method_stack + MAXSTACKSIZE);
00166     last_exception = this;
00167     stack_size = backtrace(method_stack, MAXSTACKSIZE);
00168 }

GenericException * GenericException::lastException void   )  [static]
 

Definition at line 58 of file GenericException.cc.

References last_exception.

00059 {
00060     return last_exception;
00061 }

virtual String* Core::GenericException::notifierString void   )  [virtual]
 

Reimplemented in Core::Error, External::ExternalObjectNotFoundError, External::LibraryNotFoundError, Core::FileOpenFailed, Core::IncompleteNextCountError, Core::KeyNotFoundError, Net::NetworkError, Net::UnknownHostError, Core::NotFoundError, Core::OSError, Core::PositionOutOfBoundsError, Core::SubscriptOutOfBoundsError, Tools::CommandLineMissingArgument, Tools::CommandLineParserError, Tools::CommandLineUnknownArgument, Tools::CommandLineUnsufficientParameters, and Core::ValueNotFoundError.

Referenced by description().

void GenericException::originator const Object object  )  [virtual]
 

Definition at line 77 of file GenericException.cc.

References _originator.

00078 {
00079     _originator = object;
00080 }

const Object * GenericException::originator void   )  [virtual]
 

Definition at line 71 of file GenericException.cc.

References _originator, and nil.

Referenced by raiseFrom().

00072 {
00073     if (_originator == nil) return this;
00074                        else return _originator;
00075 }

Object * GenericException::parameter void   )  [virtual]
 

Definition at line 82 of file GenericException.cc.

References _parameter.

00083 {
00084     return _parameter;
00085 }

void GenericException::pass void   )  [virtual]
 

Passes (propagates) the exception thru the rest of stack.

In fact it calls privRaise to throw the receiver again.

Definition at line 138 of file GenericException.cc.

References privRaise().

Referenced by OS::Promise::value().

00139 {
00140     privRaise();
00141 }

void GenericException::printStackOn Stream stream  )  [virtual]
 

Definition at line 103 of file GenericException.cc.

References Core::String::copy(), Core::String::demangleMethodName(), Core::String::indexOf(), Core::Stream::lf(), method_stack, Core::String::nextIndexOf(), Core::Stream::nextPutAll(), Core::String::size(), and stack_size.

Referenced by Tools::Application::defaultExceptionHandler().

00104 {
00105     if (method_stack == NULL || stack_size <= 1) {
00106         stream->nextPutAll("No stack.");
00107         return;
00108     }
00109 
00110     char **names;
00111     String *line, *module, *mangledName;
00112     int startMark, endMark;
00113 
00114     names = backtrace_symbols(method_stack, stack_size);
00115     for (int i = 1; i < stack_size; i++) {
00116         line = new String(names[i]);
00117         startMark = line->indexOf('(');
00118         if (startMark < 0) startMark = line->indexOf(' ');
00119         endMark = line->nextIndexOf('+', startMark, line->size());
00120         module = dynamic_cast<String *>(line->copy(0, startMark));
00121         mangledName = dynamic_cast<String *>(line->copy(startMark+1, endMark));
00122 
00123         stream->nextPutAll("    ");
00124         try {
00125             stream->nextPutAll(mangledName->demangleMethodName());
00126         }
00127         catch (GenericException *ex) {
00128             stream->nextPutAll(mangledName);
00129         }
00130         stream->nextPutAll(" in ");
00131         stream->nextPutAll(module);
00132         stream->lf();
00133     }
00134     free((void *) names);
00135 }

virtual void Core::GenericException::privRaise void   )  [protected, virtual]
 

This method really throws the receiver as an exception.

Every subclass MUST reimplement this method, even if it's parent does. This is because of poor object type handling in C++. :-(

Reimplemented in Core::Error, External::ExternalObjectNotFoundError, External::LibraryNotFoundError, Core::FileOpenFailed, Core::IncompleteNextCountError, Core::KeyNotFoundError, Net::NetworkError, Net::UnknownHostError, Core::NotFoundError, Core::OSError, Core::PositionOutOfBoundsError, Core::SubscriptOutOfBoundsError, Tools::CommandLineMissingArgument, Tools::CommandLineParserError, Tools::CommandLineUnknownArgument, Tools::CommandLineUnsufficientParameters, and Core::ValueNotFoundError.

Referenced by pass(), and raise().

void GenericException::raise void   )  [virtual]
 

Raises (throws) the receiver as an exception.

In fact it calls privRaise to do so.

Definition at line 149 of file GenericException.cc.

References getExecutionStack(), and privRaise().

Referenced by Core::FileAccessor::FileAccessor(), OS::Environment::getEnv(), and raiseFrom().

00150 {
00151     getExecutionStack();
00152     privRaise();
00153 }

void GenericException::raiseFrom const Object origin  )  [virtual]
 

Definition at line 143 of file GenericException.cc.

References originator(), and raise().

Referenced by Net::SocketAccessor::accept(), Core::OrderedCollection::at(), Core::ByteArray::at(), Core::Array::at(), Net::SocketAccessor::bindTo(), Core::ByteArray::checkObject(), Net::SocketAccessor::connectTo(), Core::Object::error(), Net::SocketAccessor::listenFor(), Core::OrderedCollection::put(), Core::ByteArray::put(), Core::Array::put(), Core::ExternalStream::setPosition(), and Net::SocketAccessor::SocketAccessor().

00144 {
00145     originator(origin);
00146     raise();
00147 }

String * GenericException::selector void   )  [virtual]
 

Definition at line 97 of file GenericException.cc.

References _selector.

00098 {
00099     return _selector;
00100 }

void GenericException::selector const char *  sel  )  [virtual]
 

Definition at line 92 of file GenericException.cc.

References _selector.

00093 {
00094     _selector = new String(sel);
00095 }

void GenericException::selector String sel  )  [virtual]
 

Definition at line 87 of file GenericException.cc.

References _selector.

00088 {
00089     _selector = sel;
00090 }

void GenericException::visitBy Visitor visitor  )  [virtual]
 

Reimplemented from Core::Object.

Definition at line 156 of file GenericException.cc.

References Core::Visitor::visitException().

00157 {
00158     visitor->visitException(this);
00159 }


Member Data Documentation

const Object* Core::GenericException::_originator [protected]
 

Definition at line 44 of file GenericException.h.

Referenced by GenericException(), and originator().

Object* Core::GenericException::_parameter [protected]
 

Definition at line 45 of file GenericException.h.

Referenced by GenericException(), and parameter().

String* Core::GenericException::_selector [protected]
 

Definition at line 43 of file GenericException.h.

Referenced by GenericException(), and selector().

GenericException * GenericException::last_exception = nil [static, protected]
 

Definition at line 36 of file GenericException.cc.

Referenced by getExecutionStack(), and lastException().

String* Core::GenericException::messageText [protected]
 

Definition at line 42 of file GenericException.h.

Referenced by description(), GenericException(), and Net::UnknownHostError::UnknownHostError().

void* Core::GenericException::method_stack[MAXSTACKSIZE] [private]
 

Definition at line 51 of file GenericException.h.

Referenced by getExecutionStack(), and printStackOn().

int Core::GenericException::stack_size [private]
 

Definition at line 52 of file GenericException.h.

Referenced by GenericException(), getExecutionStack(), and printStackOn().


The documentation for this class was generated from the following files:
Generated on Mon Nov 27 09:51:32 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2