home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / iexcept.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  9.8 KB  |  301 lines

  1.  
  2.  
  3. #ifndef _IEXCEPT_
  4. #define _IEXCEPT_
  5. /*******************************************************************************
  6. * FILE NAME: iexcept.hpp                                                       *
  7. *                                                                              *
  8. * DESCRIPTION:                                                                 *
  9. *   Declaration of the classes                                                 *
  10. *     IBaseErrorInfo                                                           *
  11. *     IGUIErrorInfo                                                            *
  12. *     ISystemErrorInfo                                                         *
  13. *     ICLibErrorInfo                                                           *
  14. *     IXLibErrorInfo                                                           *
  15. *                                                                              *
  16. *   This file also contains several macros and functions which can be used     *
  17. *   to facilitate throwing exceptions.  This includes the IASSERTPARM and      *
  18. *   IASSERTSTATE macros, and the IExcept__assertParameter and                  *
  19. *   IExcept__assertState functions.                                            *
  20. *                                                                              *
  21. * COPYRIGHT:                                                                   *
  22. *   IBM Open Class Library                                                     *
  23. *   (C) Copyright International Business Machines Corporation 1992, 1996       *
  24. *   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
  25. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  26. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  27. *                                                                              *
  28. *******************************************************************************/
  29. #include <ivbase.hpp>
  30. #include <iexcbase.hpp>
  31.  
  32. #pragma pack(4)
  33.  
  34.  
  35.  
  36. class IBaseErrorInfo : public IVBase {
  37. typedef IVBase
  38.   Inherited;
  39. public:
  40. /*------------------------------- Constructors ------------------------------ */
  41.  IBaseErrorInfo  ( );
  42.  
  43. virtual
  44.  ~IBaseErrorInfo ( );
  45.  
  46. /*---------------------------- Error Information -----------------------------*/
  47. virtual
  48.   operator const char* ( ) const = 0;
  49.  
  50. virtual const char
  51.  *text ( ) const = 0;
  52.  
  53. virtual unsigned long
  54.   errorId ( ) const = 0;
  55.  
  56. virtual Boolean
  57.   isAvailable ( ) const = 0;
  58.  
  59. enum ExceptionType { accessError, deviceError, invalidParameter,
  60.                      invalidRequest, outOfSystemResource, outOfWindowResource,
  61.                      outOfMemory, resourceExhausted };
  62.  
  63. /*------------------------------ Throw Support -------------------------------*/
  64. void
  65.   throwError ( const IExceptionLocation&  location,
  66.                ExceptionType              name = accessError,
  67.                IException::Severity       severity = recoverable,
  68.                IException::ErrorCodeGroup errorGroup =
  69.                                              IException::baseLibrary );
  70.  
  71.  
  72.  
  73.  
  74. }; // IBaseErrorInfo
  75.  
  76. #ifdef IUSE_IERRORINFO
  77.   typedef IBaseErrorInfo IErrorInfo;
  78. #endif
  79.  
  80. class IGUIErrorInfo : public IBaseErrorInfo {
  81. typedef IBaseErrorInfo
  82.   Inherited;
  83. public:
  84. /*------------------------------- Constructors -------------------------------*/
  85.   IGUIErrorInfo ( const char* GUIFunctionName = 0 );
  86.  
  87. virtual
  88.  ~IGUIErrorInfo ( );
  89.  
  90. /*---------------------------- Error Information -----------------------------*/
  91. virtual
  92.   operator const char* ( ) const;
  93.  
  94. virtual const char
  95.  *text ( ) const;
  96.  
  97. virtual unsigned long
  98.   errorId ( ) const;
  99.  
  100. virtual Boolean
  101.   isAvailable ( ) const;
  102.  
  103. /*------------------------------ Throw Support -------------------------------*/
  104. static void
  105.   throwGUIError  ( const char*               functionName,
  106.                    const IExceptionLocation& location,
  107.                    IBaseErrorInfo::ExceptionType name = accessError,
  108.                    IException::Severity      severity = recoverable );
  109.  
  110. private:
  111. /*----------------------------- Hidden Functions -----------------------------*/
  112.   IGUIErrorInfo ( const IGUIErrorInfo& errorInformation );
  113.  
  114. IGUIErrorInfo
  115.  &operator= ( const IGUIErrorInfo& errorInformation );
  116.  
  117. /*--------------------------------- Private ----------------------------------*/
  118.   unsigned long
  119.     ulClErrorId;
  120.  
  121.  
  122. char
  123.  *pClFuncNameText;
  124.  
  125.  
  126.  
  127.  
  128. }; // IGUIErrorInfo
  129.  
  130. class ISystemErrorInfo : public IBaseErrorInfo {
  131. typedef IBaseErrorInfo
  132.   Inherited;
  133. public:
  134. /*------------------------------- Constructors -------------------------------*/
  135.   ISystemErrorInfo ( unsigned long systemErrorId,
  136.                      const char* systemFunctionName = 0 );
  137.  
  138. virtual
  139.  ~ISystemErrorInfo ( );
  140.  
  141. /*---------------------------- Error Information -----------------------------*/
  142. virtual
  143.   operator const char* ( ) const;
  144.  
  145. virtual const char
  146.  *text ( ) const;
  147.  
  148. virtual unsigned long
  149.   errorId ( ) const;
  150.  
  151. virtual Boolean
  152.   isAvailable ( ) const;
  153.  
  154. /*------------------------------ Throw Support -------------------------------*/
  155. static void
  156.   throwSystemError ( unsigned long             systemErrorId,
  157.                      const char*               functionName,
  158.                      const IExceptionLocation& location,
  159.                      IBaseErrorInfo::ExceptionType name = accessError,
  160.                      IException::Severity      severity = recoverable );
  161.  
  162. private:
  163.   ISystemErrorInfo ( const ISystemErrorInfo& errorInformation );
  164.  
  165. ISystemErrorInfo
  166.  &operator= ( const ISystemErrorInfo& errorInformation );
  167.  
  168. /*--------------------------------- Private ----------------------------------*/
  169. Boolean
  170.   bClError;
  171. unsigned long
  172.   ulClErrorId;
  173. char
  174.  *pClErrorText;
  175.  
  176.  
  177.  
  178. }; // ISystemErrorInfo
  179.  
  180. class ICLibErrorInfo : public IBaseErrorInfo {
  181. typedef IBaseErrorInfo
  182.   Inherited;
  183. public:
  184. /*------------------------------- Constructors -------------------------------*/
  185. ICLibErrorInfo ( const char* CLibFunctionName = 0 );
  186.  
  187. virtual
  188.  ~ICLibErrorInfo ( );
  189.  
  190. /*---------------------------- Error Information -----------------------------*/
  191. virtual
  192. operator const char* ( ) const;
  193.  
  194. virtual const char
  195.  *text ( ) const;
  196.  
  197. virtual unsigned long
  198.   errorId ( ) const;
  199.  
  200. virtual Boolean
  201.   isAvailable ( ) const;
  202.  
  203. /*------------------------------ Throw Support -------------------------------*/
  204. static void
  205.   throwCLibError (   const char*               functionName,
  206.                      const IExceptionLocation& location,
  207.                      IBaseErrorInfo::ExceptionType name = accessError,
  208.                      IException::Severity      severity = recoverable );
  209.  
  210. private:
  211. /*----------------------------- Hidden Functions -----------------------------*/
  212.   ICLibErrorInfo ( const ICLibErrorInfo& errorInformation );
  213.  
  214. ICLibErrorInfo
  215.  &operator= ( const ICLibErrorInfo& errorInformation );
  216.  
  217. /*--------------------------------- Private ----------------------------------*/
  218. Boolean
  219.   bClError;
  220. unsigned long
  221.   ulClErrno;
  222. char
  223.  *pClErrorText;
  224.  
  225.  
  226.  
  227.  
  228. }; // IClibErrorInfo
  229.  
  230.  
  231.  
  232.  
  233. void
  234.   IExcept__assertParameter    ( const char*               assertExpression,
  235.                                 const IExceptionLocation& location ),
  236.   IExcept__assertState        ( const char*               assertExpression,
  237.                                 const IExceptionLocation& location ),
  238.   IExcept__throwLibraryError  (
  239.               unsigned long             messageId,
  240.               const IExceptionLocation& location,
  241.               IBaseErrorInfo::ExceptionType name =
  242.                                             IBaseErrorInfo::invalidRequest,
  243.               IException::Severity      severity = IException::recoverable,
  244.               const char*               text = 0),
  245.   IExcept__throwError (
  246.               unsigned long              messageId,
  247.               const IExceptionLocation&  location,
  248.               const char*                messageFile,
  249.               IException::ErrorCodeGroup errorGroup,
  250.               IBaseErrorInfo::ExceptionType  name =
  251.                                          IBaseErrorInfo::invalidRequest,
  252.               IException::Severity       severity = IException::recoverable,
  253.               const char*                substitutionText = 0);
  254.  
  255. #define IASSERTPARM(test)\
  256.     if(!(test))\
  257.     {\
  258.        IExcept__assertParameter(#test, IEXCEPTION_LOCATION());\
  259.     }
  260.  
  261. #define IASSERTSTATE(test)\
  262.     if(!(test))\
  263.     {\
  264.        IExcept__assertState(#test, IEXCEPTION_LOCATION());\
  265.     }
  266.  
  267. #define ITHROWGUIERROR(func)\
  268.     IGUIErrorInfo::throwGUIError(func, IEXCEPTION_LOCATION())
  269.  
  270. #define ITHROWGUIERROR2(func, exType, sev)\
  271.     IGUIErrorInfo::throwGUIError(func, IEXCEPTION_LOCATION(), exType, sev)
  272.  
  273. #define ITHROWSYSTEMERROR(id, func, exType, sev)\
  274.     ISystemErrorInfo::throwSystemError(id, func, \
  275.                                        IEXCEPTION_LOCATION(), exType, sev)
  276.  
  277. #define ITHROWCLIBERROR(func, exType, sev)\
  278.     ICLibErrorInfo::throwCLibError(func, IEXCEPTION_LOCATION(), exType, sev)
  279.  
  280.  
  281. #define ITHROWLIBRARYERROR(id, exType, sev)\
  282.     IExcept__throwLibraryError(id, IEXCEPTION_LOCATION(), exType, sev)
  283.  
  284. #define ITHROWLIBRARYERROR1(id, exType, sev, text)\
  285.     IExcept__throwLibraryError(id, IEXCEPTION_LOCATION(), exType, sev, text)
  286.  
  287. #define ITHROWERROR(messageId, name, severity, messageFile, errorGroup)\
  288.     IExcept__throwError(messageId, IEXCEPTION_LOCATION(), messageFile, \
  289.                         errorGroup, name, severity)
  290.  
  291. #define ITHROWERROR1(messageId, name, severity, messageFile,\
  292.                      errorGroup, substitutionText)\
  293.     IExcept__throwError(messageId, IEXCEPTION_LOCATION(), messageFile, \
  294.                         errorGroup, name, severity, substitutionText)
  295.  
  296. #pragma pack()
  297.  
  298. #endif /* _IEXCEPT_ */
  299.  
  300.  
  301.