Figure 3: The class declaration for EXBase_c

// COPYRIGHT (c) 1997, TRIAD Systems, Inc. Permission is granted
// to use this code as long as this copyright notice appears in
// all source files

#ifndef __EXBASE_H__
#define __EXBASE_H__
#include <stdexcept>
#include <utility>
#include <vector>
#include <windows.h>
#include <winnt.h>
using namespace std;

#ifdef _USRDLL
  #define SCOPE __declspec(dllexport)
#else
  #define SCOPE __declspec(dllimport)
#endif

#pragma warning(disable:4251) // CLIENTS HAVE NO ACCESS TO 
                              // PRIVATE STATIC MEMBERS, THEREFORE 
                              // THIS WARNING IS MEANINGLESS

class SCOPE EXBase_c //: public exception
{ // EXCEPTION CLASSES CAN'T THROW EXCEPTIONS!
  public: // TYPDEFS, ENUMERATIONS AND SUCH
    typedef pair<int,HMODULE>       ModulePair_t;
    typedef vector<ModulePair_t>    Modules_t;
    typedef enum Severity_e 
      { EXNone = 0, EXTrace, EXWarning, EXError, EXFatal };
    #define SEVERITY_MASK 0xC0000000
    #define FACILITY_MASK 0x0FFF0000
    #define MSG_ID_MASK 0x0000FFFF
  private: // SANITY CHECKING FUNCTIONS AND VARIABLES
    static const long  sm_clSerialNumber; // CLASS WIDE VALUE
    mutable long       m_clSerialNumber;  // INSTANCE LEVEL VALUE
    void SanityCheck() const throw(logic_error);
    void SetSanity()   const throw(logic_error);
    void ClearSanity() const throw(logic_error);
  private: // MEMBER VARIABLES
    string      m_Message;
    string      m_UserMessage;
    DWORD       m_dwError;
    Severity_e  m_eSeverity;
    string      m_Source;
    string      m_File;
    int         m_iLine;
  private: // USED BY THE STATIC FUNCTIONS FOR SYSTEMIC 
           // EXCEPTION HANDLING
    static  Modules_t               m_RegisteredApps;
    static  _se_translator_function m_OldSEHandler;
    static  terminate_function      m_OldTerminationHandler;
    static  unexpected_function     m_OldUnexpectedHandler;
  protected:
    void          Log(string const&) throw();
    bool          IsSystemError() throw();
    string        BuildHeader(string const&) throw();    bool          IsAppError() throw();
    bool          GetErrorMessage(int const, 
                    HMODULE hModule = NULL) throw();
    bool          LogError(string const& header);
    string const& Source(string const&) throw();
  private: // CAN ONLY BE USED BY THIS CLASS
    EXBase_c() throw(); // ONLY USE FOR UNEXPECTED EXCEPTIONS 
                        // (I.E.: WITHIN AN EXCEPTION CLASS)
  protected: // THIS CLASS CAN'T BE INSTANTIATED DIRECTLY.
    EXBase_c(int iLine, string const& Source, string const& Msg,
      Severity_e eSeverity,type_info const& Type) throw();
    EXBase_c(int iLine, string const& Source, long lErr,
      Severity_e eSeverity,type_info const& Type) throw();
    EXBase_c(int iLine, string const& Source, long lErr,
      string const& Msg, Severity_e eSeverity, 
      type_info const& Type) throw();
  public: // OTHERWISE WE CAN'T DESTROY THESE OBJECTS
    virtual ~EXBase_c() throw();
  public: // MEMBER ACCESS FUNCTIONS
    string const&    Message() const throw();
    string const&    Source() const throw();
    DWORD const      Error() const throw();
    Severity_e const Severity() const throw();
  public: // ONE TIME CALL PER THREAD - SETS AND RESETS REROUTING
          // MECHANISMS, RESPECTIVELY
    // REROUTES ERROR HANDLING ROUTINES
    static void Initialize() throw();   
    // RESETS THE ORIGINAL FUNCTIONS
    static void DeInitialize() throw();                                      
  public: // ONE TIME CALL PER APP OR LIBRARY - ADDS AND DELETES 
          // MESSAGE TABLES FROM THE LIST, RESPECTIVELY
    // ADDS THIS MESSAGE TABLE
    static bool Register(string const&, 
      DWORD const dwFacility = 0) throw(); 
    // REMOVES THIS MESSAGE TABLES
    static bool UnRegister(DWORD const) throw();                               
  private: // EXCEPTION REDIRECTION FUNCTIONS
    // REROUTES STRUCTURED EXCEPTIONS
    static void WinException(unsigned int,EXCEPTION_POINTERS*);                
    // TERMINATION HANDLER
    static void Bail();                                                        
    // UNEXPECTED EXCEPTION HANDLER
    static void Unexpected();                                                  
  private: // LOOKUP AND MANIPULATION FUNCTION OF REGISTRATION 
           // VECTOR
    static  Find(long const) throw();
};

#endif // __EXBASE_H__

/* End of File */