home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IEXCEPT.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
24KB
|
400 lines
#ifndef _IEXCEPT_
#define _IEXCEPT_
/*******************************************************************************
* FILE NAME: iexcept.hpp *
* *
* DESCRIPTION: *
* Declaration of the classes: *
* IErrorInfo - Abstract base class for the following 2 classes. *
* IGUIErrorInfo - Used to get exception information from the *
* windowing system. *
* ISystemErrorInfo - Used to get exception information from the *
* operating system. *
* *
* This file also contains several macros and functions which can be used *
* to facilitate throwing exceptions. This includes the IASSERTPARM and *
* IASSERTSTATE macros, and the IExcept__assertParameter and *
* IExcept__assertState functions. *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IVBASE_
#include <ivbase.hpp>
#endif
#ifndef _IEXCBASE_
#include <iexcbase.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
class IErrorInfo : public IVBase {
typedef IVBase
Inherited;
/*******************************************************************************
* The IErrorInfo class is an abstract base class that defines the interface *
* for its subclasses, IGUIErrorInfo and ISystemErrorInfo. IGUIErrorInfo is *
* used to obtain information about Presentation Manager errors and *
* ISystemErrorInfo is used to obtain information about OS/2 errors. *
* *
* The following macros and functions assist in throwing exceptions: *
* *
* IASSERTPARM - This macro accepts an expression to be tested as *
* input. The expression is asserted to be true. *
* If it evaluates to false, it invokes the *
* IExcept__assertParameter function, which creates *
* an IInvalidParameter exception. Location *
* information is added to the exception, which is *
* then logged and thrown. *
* IASSERTSTATE - This macro accepts an expression to be tested as *
* input. The expression is asserted to be true. *
* If it evaluates to false, it invokes the *
* IExcept__assertState function, which creates an *
* IInvalidRequest exception. Location information *
* is added to the exception, which is then logged *
* and thrown. *
* ITHROWLIBRARYERROR - This macro takes three arguments: *
* - The ID of the message to be loaded from the *
* User Interface Class Library message file *
* - One of the values of the *
* IErrorInfo::ExceptionType enumeration, which *
* indicates the type of exception to be *
* created *
* - One of the values of the *
* IException::Severity enumeration, which *
* indicates the severity of the exception *
* The macro calls the IExcept__::throwLibraryError *
* function, which loads the message text from the *
* message file and uses it to create an exception *
* instance, adds location information, logs out *
* the exception data, and throws the exception. *
* ITHROWLIBRARYERROR1 - This macro is identical to the ITHROWLIBRARYERROR *
* macro except it has a fourth argument, which is *
* text to be substituted into the retrieved message. *
*******************************************************************************/
public:
/*-------------------------------- Destructor ----------------------------------
| This class has a destructor. |
------------------------------------------------------------------------------*/
virtual
~IErrorInfo ( );
/*-------------------------------- Accessors -----------------------------------
| These functions and conversion operator provide means of getting the |
| accessible attributes of instances of this class. All the functions and the |
| conversion operator are pure virtual. |
| operator const char* - Returns the error text. |
| text - Returns the error text. |
| errorId - Returns the error ID. |
| isAvailable - Returns true if error information is available; |
| otherwise, it returns false. |
------------------------------------------------------------------------------*/
virtual operator const char* () const = 0;
virtual const char
*text ( ) const = 0;
virtual unsigned long
errorId ( ) const = 0;
virtual Boolean
isAvailable ( ) const = 0;
/*------------------------------ Related Type ---------------------------------
| The following enumeration type is defined to pass "modes" to various |
| implementation functions and macros: |
| ExceptionType - Used to specify the type of exception to be created. The |
| allowable values are: |
| accessError - Creates an IAccessError instance. |
| deviceError - Creates an IDeviceError instance. |
| invalidParameter - Creates an IInvalidParameter instance. |
| invalidRequest - Creates an IInvalidRequest instance. |
| outOfSystemResource - Creates an IOutOfSystemResource instance. |
| outOfWindowResource - Creates an IOutOfWindowResource instance. |
| outOfMemory - Creates an IOutOfMemory instance. |
| resourceExhausted - Creates an IResourceExhausted instance. |
------------------------------------------------------------------------------*/
enum ExceptionType { accessError, deviceError, invalidParameter,
invalidRequest, outOfSystemResource, outOfWindowResource,
outOfMemory, resourceExhausted };
}; // IErrorInfo
class IGUIErrorInfo : public IErrorInfo {
typedef IErrorInfo
Inherited;
/*******************************************************************************
* The IGUIErrorInfo class allows you to obtain information about the last *
* error that occurred on a call to Presentation Manager. *
* *
* Typically, an instance of this class is created when an error condition has *
* been detected and an exception is going to be thrown. The error text *
* can be used to construct an IException subclass instance. *
* *
* The following macros are provided for throwing exceptions *
* constructed with IGUIErrorInfo information: *
* *
* ITHROWGUIERROR - This macro takes as its only argument the name of the *
* GUI function that returned an error code. It calls *
* the IGUIError::throwGUIError function, which creates *
* an IGUIError instance and uses it to create an *
* IAccessError instance, adds location information, logs *
* out the exception data, and throws the exception. *
* Note: The exception Severity is set to recoverable. *
* *
* ITHROWGUIERROR2 - This macro takes three arguments: *
* - The name of the GUI function that returned an *
* error code. *
* - One of the values of the *
* IErrorInfo::ExceptionType enumeration, which *
* indicates the type of exception to be created. *
* - One of the values of the *
* IException::Severity enumeration, which indicates *
* the severity of the exception. *
* The macro calls IGUIError::throwGUIError, which *
* creates an IGUIError instance and uses it to create an *
* exception instance, adds location information, logs out *
* the exception data, and throws the exception. *
* *
* Example: *
* *
* The following example illustrates using this class to obtain error text, *
* and using that text to construct and throw an exception: *
* *
* void* pv = WinQueryWindowPtr(hCl, sThisPtrOffset); *
* if (pv == 0) *
* { *
* IGUIErrorInfo myErr("WinQueryWindowPtr"); *
* IAccessError exc(myErr.text(), myErr.errorId()); *
* ITHROW(exc); *
* } *
* *
* An easier way to accomplish this is: *
* *
* ITHROWGUIERROR("WinQueryWindowPtr"); *
* *
*******************************************************************************/
public:
/*------------------------ Constructor/Destructor ------------------------------
| There is only one way to construct instances of this class. If the name of |
| the failing API is passed in, it will be prefixed to the error text. If |
| the error text cannot be loaded, the following default text is provided: |
| "No error text is available." |
------------------------------------------------------------------------------*/
IGUIErrorInfo ( const char* GUIFunctionName = 0 );
virtual
~IGUIErrorInfo ( );
/*-------------------------------- Accessors -----------------------------------
| These functions and conversion operator provide means of getting the |
| accessible attributes of instances of this class: |
| operator const char* - Returns the error text. |
| text - Returns the error text. |
| errorId - Returns the error ID. |
| isAvailable - Returns true if error information is available; |
| otherwise, it returns false. |
------------------------------------------------------------------------------*/
virtual operator const char* () const;
virtual const char
*text ( ) const;
virtual unsigned long
errorId ( ) const;
virtual Boolean
isAvailable ( ) const;
/*------------------------------ Throw Support ---------------------------------
| The following functions provide support for throwing exceptions using |
| information from an IGUIErrorInfo instance. The first function is |
| is used by the ITHROWGUIERROR macro: |
| throwGUIError - Creates an IGUIErrorInfo instance and uses the text from |
| it to create an exception instance, adds the |
| location information to it, logs out the exception data, |
| and throws the exception. |
| throwError - Creates an exception instance from the IGUIErrorInfo |
| instance, adds the location information to it, logs out |
| the exception data, and throws the exception. |
------------------------------------------------------------------------------*/
static void
throwGUIError ( const char* functionName,
const IExceptionLocation& location,
IErrorInfo::ExceptionType name = accessError,
IException::Severity severity = recoverable );
void
throwError ( const IExceptionLocation& location,
IErrorInfo::ExceptionType name = accessError,
IException::Severity severity = recoverable );
private:
/*--------------------------------- PRIVATE ----------------------------------*/
void
*perrinfoCl;
char
*pClFuncNameText;
IGUIErrorInfo ( const IGUIErrorInfo& errorInformation );
IGUIErrorInfo
&operator= ( const IGUIErrorInfo& errorInformation );
}; // IGUIErrorInfo
class ISystemErrorInfo : public IErrorInfo {
typedef IErrorInfo
Inherited;
/*******************************************************************************
* The ISystemErrorInfo class allows you to obtain information about an error *
* on a call to OS/2. *
* Typically an instance of this class is created when an error condition has *
* been detected, and an exception is going to be thrown. The error text *
* can be used to construct an IException subclass instance. *
* *
* The following macro is provided for throwing exceptions constructed with *
* ISystemErrorInfo information: *
* *
* ITHROWSYSTEMERROR - This macro takes four arguments: *
* - The error ID returned from the system function. *
* - The name of the system function that returned *
* an error code. *
* - One of the values of the *
* IErrorInfo::ExceptionType enumeration, which *
* indicates the type of exception to be created. *
* - One of the values of the IException::Severity *
* enumeration, which indicates the severity of the *
* exception. *
* *
* The macro calls ISystemErrorInfo::throwSystemError, which creates an *
* ISystemErrorInfo instance and uses it to create an exception instance, *
* adds location information, logs out the exception data, and throws the *
* exception. *
* *
* Example: *
* *
* The following example demonstrates usage of this class to obtain error text,*
* and construct and throw an exception: *
* *
* unsigned long ulErrCode = DosFreeModule(hmodResource); *
* if (ulErrCode) *
* { *
* ISystemErrorInfo myErr(ulErrCode, "DosFreeModule"); *
* IAccessError exc(myErr.text(), myErr.errorId()); *
* ITHROW(exc); *
* } *
* *
*******************************************************************************/
public:
/*------------------------ Constructor/Destructor -----------------------------
| There is only one way to construct instances of this class. An |
| ISystemErrorInfo object requires one argument, an error ID, identifying an |
| operating system error. If the name of the failing API is passed in, it |
| will be prefixed to the error text. If the error text cannot be loaded, |
| the following default text is provided: "No error text is available." |
------------------------------------------------------------------------------*/
ISystemErrorInfo ( unsigned long systemErrorId,
const char* systemFunctionName = 0 );
virtual
~ISystemErrorInfo ( );
/*-------------------------------- Accessors -----------------------------------
| These functions and conversion operator provide a means of getting the |
| accessible attributes of instances of this class: |
| operator const char* - Returns the error text. |
| text - Returns the error text. |
| errorId - Returns the error ID. |
| isAvailable - Returns true if error information is available; |
| otherwise, it returns false. |
------------------------------------------------------------------------------*/
virtual operator const char* () const;
virtual const char
*text ( ) const;
virtual unsigned long
errorId ( ) const;
virtual Boolean
isAvailable ( ) const;
/*------------------------------ Throw Support ---------------------------------
| The following function is used by the ITHROWSYSTEMERROR macro: |
| throwSystemError - Creates an ISystemErrorInfo instance and uses the text |
| from it to create an exception instance, adds the |
| location information to it, logs out the exception |
| data, and throws the exception. |
------------------------------------------------------------------------------*/
static void
throwSystemError ( unsigned long systemErrorId,
const char* functionName,
const IExceptionLocation& location,
IErrorInfo::ExceptionType name = accessError,
IException::Severity severity = recoverable );
private:
/*--------------------------------- PRIVATE ----------------------------------*/
Boolean
bClError;
unsigned long
ulClErrorId;
char
*pClErrorText;
ISystemErrorInfo ( const ISystemErrorInfo& errorInformation );
ISystemErrorInfo
&operator= ( const ISystemErrorInfo& errorInformation );
}; // ISystemErrorInfo
void
IExcept__assertParameter ( const char* assertExpression,
const IExceptionLocation& location ),
IExcept__assertState ( const char* assertExpression,
const IExceptionLocation& location ),
IExcept__throwLibraryError ( unsigned long messageId,
const IExceptionLocation& location,
IErrorInfo::ExceptionType name = IErrorInfo::invalidRequest,
IException::Severity severity = IException::recoverable,
const char* text = 0);
#define IASSERTPARM(test)\
if(!(test))\
IExcept__assertParameter(#test, IEXCEPTION_LOCATION())
#define IASSERTSTATE(test)\
if(!(test))\
IExcept__assertState(#test, IEXCEPTION_LOCATION())
#define ITHROWGUIERROR(func)\
IGUIErrorInfo::throwGUIError(func, IEXCEPTION_LOCATION())
#define ITHROWGUIERROR2(func, exType, sev)\
IGUIErrorInfo::throwGUIError(func, IEXCEPTION_LOCATION(), exType, sev)
#define ITHROWSYSTEMERROR(id, func, exType, sev)\
ISystemErrorInfo::throwSystemError(id, func, IEXCEPTION_LOCATION(), exType, sev)
#define ITHROWLIBRARYERROR(id, exType, sev)\
IExcept__throwLibraryError(id, IEXCEPTION_LOCATION(), exType, sev)
#define ITHROWLIBRARYERROR1(id, exType, sev, text)\
IExcept__throwLibraryError(id, IEXCEPTION_LOCATION(), exType, sev, text)
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#endif /* _IEXCEPT_ */