EoaCore Class Reference

#include <EoaCore.hxx>

Inheritance diagram for EoaCore:
Inheritance graph
[legend]
Collaboration diagram for EoaCore:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 EoaCore ()
virtual ~EoaCore () throw ()
const char * what (void) const throw ()
void AppendWhat (const char *child)

Static Public Attributes

static unsigned int gBacktraceSymbols = 5
 The number of backtrace symbols to add to the "what" string.

Private Attributes

char fWhat [2048]
 What exception generated this object.

Detailed Description

The root exception for all exceptions explicitly thrown by the oaCore library. All exceptions declared by this library should be derived from this class, and not std::exception. New exceptions can be derived from EoaCore by creating a new class

 class EoaChild :public EoaCore {
 public:
     EoaChild() {AppendWhat("EoaChild");};
 };

But the prefered way to create derived exception classes is to use the OA_EXCEPTION macro. This is used as follows

 OA_EXCEPTION(EChild,EoaCore);
 OA_EXCEPTION(EGrandChild,EChild);
 ...
 try {
   throw EChild();
 }
 catch (EoaCore& ex) {
   std::cout << ex.what << std::endl;
 }

This can add a backtrace at the point of the exception. The number of backtrace frames to be shown is controlled with the EoaCore::gBacktraceSymbols static variable.

Definition at line 45 of file EoaCore.hxx.


Constructor & Destructor Documentation

EoaCore::EoaCore (  ) 

Definition at line 13 of file EoaCore.cxx.

References fWhat, and gBacktraceSymbols.

00013                  {
00014     fWhat[0] = 0;
00015 #ifdef _GNU_SOURCE
00016     if (gBacktraceSymbols>0) {
00017         const unsigned int bufferSize=100;
00018         if (gBacktraceSymbols>bufferSize) gBacktraceSymbols = bufferSize;
00019         void *buffer[bufferSize];
00020         unsigned int frames = bufferSize;
00021         if (gBacktraceSymbols<frames) frames = gBacktraceSymbols;
00022         int nFrames = backtrace(buffer,frames);
00023         char **symbols = backtrace_symbols(buffer,nFrames);
00024         if (symbols != NULL) {
00025             unsigned int len = 0;
00026             std::strcat(fWhat,"Backtrace:\n");
00027             for (int i = 0; i<nFrames; ++i) {
00028                 std::string sym(symbols[i]);
00029                 std::string lib;
00030                 std::string::size_type s = sym.find_last_of('/');
00031                 if (s != std::string::npos) sym = sym.substr(s+1);
00032                 s = sym.find_first_of('(');
00033                 if (s != std::string::npos) lib = sym.substr(0,s);
00034                 sym = sym.substr(s+1);
00035                 std::string::size_type t = sym.find_first_of(')');
00036                 if (s != std::string::npos
00037                     && t != std::string::npos) sym = sym.substr(0,t);
00038                 else sym="";
00039                 if (lib.empty() && sym.empty()) continue;
00040                 len += lib.length();
00041                 len += sym.length() + 6;
00042                 if (2*len>sizeof(fWhat)) break;
00043                 std::strcat(fWhat," --> ");
00044                 if (!lib.empty()) std::strcat(fWhat,lib.c_str());
00045                 if (!sym.empty()) {
00046                     std::strcat(fWhat,": ");
00047                     std::strcat(fWhat,sym.c_str());
00048                 }
00049                 std::strcat(fWhat,"\n");
00050             }
00051             std::free(symbols);
00052         }
00053     }
00054 #endif
00055     std::strcat(fWhat,"Exception:  EoaCore");
00056 }

virtual EoaCore::~EoaCore (  )  throw () [inline, virtual]

Definition at line 54 of file EoaCore.hxx.

00054 {}


Member Function Documentation

void EoaCore::AppendWhat ( const char *  child  ) 

Used in constructors of classes which inherit EoaCore to add text to the What string. Here is a comprehensive example of how to construct an exception derived from EoaCore:

    /// class EoaChild : public EoaCore {
    /// public: 
    ///   EoaChild() {AppendWhat("EoaChild");}
    /// };
    /// 

Definition at line 58 of file EoaCore.cxx.

References fWhat.

00058                                           {
00059     unsigned int wLen = std::strlen(fWhat);
00060     unsigned int cLen = std::strlen(child);
00061     if (wLen+cLen < sizeof(fWhat)-5) {
00062         std::strcat(fWhat,"::");
00063         std::strcat(fWhat,child);
00064     }
00065 }

const char* EoaCore::what ( void   )  const throw () [inline]

Inherited from exception to return the name of the exception as a null terminated string.

Definition at line 58 of file EoaCore.hxx.

References fWhat.

00058 {return fWhat;}


Member Data Documentation

char EoaCore::fWhat[2048] [private]

What exception generated this object.

Definition at line 47 of file EoaCore.hxx.

Referenced by AppendWhat(), EoaCore(), and what().

unsigned int EoaCore::gBacktraceSymbols = 5 [static]

The number of backtrace symbols to add to the "what" string.

Definition at line 51 of file EoaCore.hxx.

Referenced by EoaCore().


The documentation for this class was generated from the following files:

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1