home *** CD-ROM | disk | FTP | other *** search
- #ifndef _IEXCBASE_
- #define _IEXCBASE_
- /****************************************************************/
- /* CLASS NAMES: IExceptionLocation */
- /* IException */
- /* IAccessError */
- /* IAssertionFailure */
- /* IDeviceError */
- /* IInvalidParameter */
- /* IInvalidRequest */
- /* IResourceExhausted */
- /* IOutOfMemory */
- /* IOutOfSystemResource */
- /* IOutOfWindowResource */
- /* */
- /* DESCRIPTION: Base exception class for exception handling */
- /* mechanism. NOTE: This header has no */
- /* dependencies on the "PM" class library. It is */
- /* capable of being used by other class librarys */
- /* and is used as the base exception class for */
- /* the Boeblingen Building Blocks. All of the */
- /* IBM Class Library: User Interface subclasses of IException are declared */
- /* here. */
- /* This file also contains all of the macros */
- /* macros required for implementing the exception */
- /* handling mechanism, including IASSERT, ITHROW, */
- /* IExceptionLocation, and IEXCLASSDECLARE. */
- /* */
- /* Hungarian notation is "exloc" */
- /* "ex" */
- /* */
- /* */
- /* $Log: R:/IBMCLASS/IBASE/VCS/IEXCBASE.HPV $ */
- //
- // Rev 1.12 25 Oct 1992 16:46:10 nunn
- //changed library name to ICLUI
- //
- // Rev 1.11 17 Oct 1992 14:54:16 BUILDER
- //added //'s to log entries
- //
- // Rev 1.10 17 Oct 1992 14:13:02 BUILDER
- // removed */, will add CommentPrefix to PVCS master config file
- //
- // Rev 1.9 17 Oct 1992 13:47:00 BUILDER
- // added missing */ at end of change description
- //
- // Rev 1.8 16 Oct 1992 19:14:48 SWEDE
- // removed change log, added check for ifdef __FUNCTION__ to
- // support all compilers
- /****************************************************************/
- /* Copyright (c) IBM Corporation 1992 */
- /****************************************************************/
-
- #define IMAX_THROWS 5
-
- typedef void (IEXCEPTIONTRACECALLBACK)(const char*);
-
- /****************************************************************/
- /* Class: IExceptionLocation */
- /****************************************************************/
- class IExceptionLocation {
- public:
- /****************************************************************/
- /* Constructor to encapsulate information on where an */
- /* exception has been thrown or re-thrown. Usually used in */
- /* conjunction with the IEXCEPTION_LOCATION macro. */
- /****************************************************************/
- IExceptionLocation(const char* fileName=0,
- const char* functionName=0,
- unsigned long lineNo=0);
-
- /****************************************************************/
- /* Function to return the path qualified file name where an */
- /* exception has been thrown or re-thrown. */
- /****************************************************************/
- const char* file() const;
-
- /****************************************************************/
- /* Function to return the name of the function which has */
- /* thrown or re-thrown an exception. */
- /****************************************************************/
- const char* function() const;
-
- /****************************************************************/
- /* Function to return the line number of the statement in the */
- /* source file from which an exception has been thrown or */
- /* re-thrown. */
- /****************************************************************/
- unsigned long lineNo() const;
-
- private:
- const char* pszClFile;
- const char* pszClFunction;
- unsigned long ulClLineNo;
- };
-
-
- enum IExceptionSeverity {recoverable, unrecoverable};
-
- /****************************************************************/
- /* Class: IException */
- /****************************************************************/
- class IException {
- public:
- /****************************************************************/
- /* Constructor to create an exception from a message string. */
- /****************************************************************/
- IException(const char* exMsgText,
- unsigned long errorId = 0,
- IExceptionSeverity exSev = unrecoverable);
-
- /****************************************************************/
- /* Copy constructor */
- /****************************************************************/
- IException(const IException& exc);
-
- virtual ~IException();
-
- /****************************************************************/
- /* Function to allow appending of text to the message string on */
- /* the top of the "stack". e.g. Call help desk at 999-999-9999 */
- /****************************************************************/
- IException& appendText(const char* exMsgText);
-
- /****************************************************************/
- /* Function to add an exception message string to the top of */
- /* the message "stack". */
- /****************************************************************/
- IException& setText(const char* exMsgText);
-
- /****************************************************************/
- /* Function to set the severity of the exception. */
- /****************************************************************/
- IException& setSeverity(IExceptionSeverity exsev);
-
- /****************************************************************/
- /* Function to set the error ID of the exception. */
- /****************************************************************/
- IException& setErrorId(unsigned long errorId);
-
- /****************************************************************/
- /* Function to return the name of the exception class. */
- /****************************************************************/
- virtual const char* name() const;
-
- /****************************************************************/
- /* Function to return an exception message string from the */
- /* "stack". Index 0, the top of the stack, is the default. */
- /****************************************************************/
- const char* text(unsigned long indexFromTop = 0) const;
-
- /****************************************************************/
- /* Function to return the number of levels of message text in */
- /* the exception message "stack". */
- /****************************************************************/
- unsigned long textCount() const;
-
- /****************************************************************/
- /* Function to return the error ID of the exception. */
- /****************************************************************/
- unsigned long errorId() const;
-
- /****************************************************************/
- /* Function to determine if the exception is deemed to be */
- /* recoverable, returns 1 if so, 0 if unrecoverable. */
- /****************************************************************/
- unsigned int isRecoverable() const;
-
- /****************************************************************/
- /* Function to add location information regarding where an */
- /* exception is thrown or re-thrown. (Stored in an array) */
- /****************************************************************/
- IException& addLocation(const IExceptionLocation& exloc);
-
- /****************************************************************/
- /* Function to return a pointer to the location information at */
- /* an index in the array of exception locations. The index is */
- /* 0 based. If an out of bounds index is passed in, a zero */
- /* pointer is returned. */
- /****************************************************************/
- const IExceptionLocation* locationAtIndex(unsigned long locIndex) const;
-
- /****************************************************************/
- /* Function to return the number of IExceptionLocation */
- /* instances stored in the array. */
- /****************************************************************/
- unsigned long locationCount() const;
-
- /****************************************************************/
- /* Function to register a callback function for use by the */
- /* logExceptionData function. This function is static and */
- /* should ONLY be invoked from one thread in a program. */
- /****************************************************************/
- static void setTraceCallback(IEXCEPTIONTRACECALLBACK* extrcCB);
-
- /****************************************************************/
- /* Function to support logging of exception instance data. If */
- /* a tracing function has been registered with the */
- /* setTraceCallback function, it is passed a buffer of data. If */
- /* no function has been registered the data is written to */
- /* STDERR. */
- /****************************************************************/
- IException& logExceptionData();
-
- /****************************************************************/
- /* Function used to terminate the application. This is part of */
- /* the termination model temporarily in place since exception */
- /* handling is not fully supported. When the compiler fully */
- /* supports exception handling this function may be removed. */
- /****************************************************************/
- void terminate();
-
-
- private:
-
- class IMsgText {
- public:
- IMsgText(const char* errText,
- const IMsgText* msgtxtOld);
- IMsgText(const IMsgText& msg);
- ~IMsgText();
-
- const char* text();
- void appendText(const char* errText);
-
- char* pszClMsg;
- IMsgText* msgtxtClNext;
-
- }; // end of IMsgText
-
- IExceptionSeverity exsevCl;
- unsigned long ulClErrorId;
- IExceptionLocation exlocClArray[IMAX_THROWS];
- unsigned long ulexlocClCount;
-
- unsigned long ulClTxtLvlCount;
- IMsgText* msgtxtClTop;
-
- void logData(char * pbuf);
- IException& operator=(const IException& exc);
- }; // end of IException
-
- #if !defined( INO_EXCEPTIONS_SUPPORT )
- #define INO_EXCEPTIONS_SUPPORT 0
- #endif
-
- /****************************************************************/
- /* Macro which creates an instance of IExceptionLocation using */
- /* the compiler defined symbols for the filename, line number, */
- /* and function name. It is primarily used by the ITHROW */
- /* macro. */
- /****************************************************************/
- #if defined ( __FUNCTION__ )
- #define IEXCEPTION_LOCATION() IExceptionLocation(__FILE__, __FUNCTION__, __LINE__)
- #else
- #define IEXCEPTION_LOCATION() IExceptionLocation(__FILE__, "Unknown", __LINE__)
- #endif
-
- /****************************************************************/
- /* Macro used to throw or re-throw an exception instance. It */
- /* uses the IEXCEPTION_LOCATION macro to capture location */
- /* information, logs the information out and then throw's the */
- /* exception. Until the compiler fully supports exception */
- /* handling, the macro terminates the program instead of throw. */
- /****************************************************************/
-
- #if (INO_EXCEPTIONS_SUPPORT)
- #define ITHROW(exc)\
- exc.addLocation(IEXCEPTION_LOCATION());\
- exc.logExceptionData();\
- exc.terminate()
- #else
- #define ITHROW(exc)\
- exc.addLocation(IEXCEPTION_LOCATION());\
- exc.logExceptionData();\
- throw exc
- #endif
-
- #define IRETHROW(exc)\
- exc.addLocation(IEXCEPTION_LOCATION());\
- exc.logExceptionData();\
- throw
-
- /****************************************************************/
- /* Macro to provide "assertion" support in the library. User */
- /* simply asserts a test, if the test is false an exception of */
- /* type IAssertionFailure is thrown. This macro will be */
- /* compiled out in the delivery version of the library for */
- /* performance reasons. */
- /****************************************************************/
- #if defined(IC_DEVELOP)
- #define IASSERT(test)\
- if(!(test))\
- {\
- IAssertionFailure assrtnfail("Failing Assertion Test Is: " #test);\
- ITHROW(assrtnfail);\
- }
- #else
- #define IASSERT(test)
- #endif
-
-
- /****************************************************************/
- /* Macro used to generate all of the declarations of the */
- /* ICLUI subclasses of IException. */
- /****************************************************************/
- #define IEXCLASSDECLARE(child,parent) class child : public parent {\
- public:\
- child(const char* a, unsigned long b = 0,\
- IExceptionSeverity c = unrecoverable);\
- virtual ~child();\
- virtual const char* name() const;\
- }
-
- /****************************************************************/
- /* Invocations of the IEXCLASSDECLARE macro. */
- /****************************************************************/
- IEXCLASSDECLARE(IAccessError,IException);
- IEXCLASSDECLARE(IAssertionFailure,IException);
- IEXCLASSDECLARE(IDeviceError,IException);
- IEXCLASSDECLARE(IInvalidParameter,IException);
- IEXCLASSDECLARE(IInvalidRequest,IException);
- IEXCLASSDECLARE(IResourceExhausted,IException);
- IEXCLASSDECLARE(IOutOfMemory,IResourceExhausted);
- IEXCLASSDECLARE(IOutOfSystemResource,IResourceExhausted);
- IEXCLASSDECLARE(IOutOfWindowResource,IResourceExhausted);
-
-
- #endif /* _IEXCBASE_ */