Listing 1: The Exception class and related macros.

class Exception : public std::exception {
//.. Implementation details
  protected :
    Exception* nestedExceptn_ ;
  public:
    Exception() ;
    Exception( const Exception &e ) ;
    Exception( unsigned int line, const string &file,
        const string &method, const string &reason,
         Exception* e = NULL ) ;
    virtual ~Exception() throw() ;
    virtual Exception* clone() const = 0 ;

    string file() const { return file_ ; }
    unsigned int line() const { return line_ ; }
    string method() const { return method_ ; }
    void method( const string &s ) { method_ = s ; }
    string reason() const { return reason_ ; }
    void reason( const string &s ) { reason_ = s ; }
    const char* what() const throw()
      { return typeid( *this ).name() ; }

    void addStackFrame( string s ) ;
    string getStackTrace( ) const { return stacktrace_ ; }

    virtual string toString( const string &tab = "" ) const ;
  private:
    void operator = ( const Exception & ) {}
};
ostream& operator << ( ostream& os, const Exception &e ) ;
#define DEFINE_EXCEPTION( excptn ) \
        class excptn : public Exception { \
      public: \
        excptn(){}\
        excptn(unsigned int line, const string &file, \
            const string &method, const string &reason,\
            Exception* e = NULL )\
            : Exception( line, file, method, reason, e ) {} \
        Exception* clone() const { Exception* e =\
            new excptn( *this ) ; return e ; }\
    }
#define THROW_EXCEPTION( excptn, msg ) { throw excptn(\
    __LINE__, __FILE__, ELF_FUNC_NAME, msg ) ; }
#define THROW_NESTD_EXCPTN( excptn, msg, nestedE ) {\
    throw excptn( __LINE__, __FILE__, ELF_FUNC_NAME, msg,\
    nestedE.clone() ) ; }
#define THROW_EXCEPTN_WWHERE( excptn, where,  msg ) {\
    throw excptn(  __LINE__, __FILE__, where, msg ) ; }
#define THROW_NESTD_EXCEPTN_WWHERE( excptn, where,  msg,\
    nestedE ) { throw excptn(  __LINE__, __FILE__, where, msg,\
    nestedE.clone() ) ; }
extern string ELF_FUNC_NAME ;