home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / taman002.zip / TASKMANA.ZIP / src / kError.h < prev    next >
C/C++ Source or Header  |  2000-04-29  |  5KB  |  210 lines

  1. /* $Id: kError.h,v 1.1 2000/04/29 19:06:34 stknut Exp $
  2.  *
  3.  * kError (kClassLib/kTaskMgr).
  4.  *
  5.  * kError     - a collection of kMyError, kDiveError and kWinError.
  6.  * kMyError   - an simple error class
  7.  * kDiveError - an simple error interface to dive errors.
  8.  * kWinError  - an simple error interface to Win-/Gpi-Api errors.
  9.  * kDosError  - an simple error interface to Dos-Api errors.
  10.  *
  11.  * Copyright (c) 1999-2000 knut st. osmundsen
  12.  *
  13.  */
  14.  
  15. #ifndef _kError_h_
  16. #define _kError_h_
  17.  
  18. #ifndef _DIVE_H_
  19.    #include <dive.h>
  20. #endif
  21.  
  22. #ifndef INCL_WINERRORS
  23.    #error ("INCL_WINERRORS is not defined");
  24. #endif
  25.  
  26.  
  27. /**
  28.  * My errors - and kPmCam errors and kTaskMgr errors.
  29.  * @author      knut st. osmundsen
  30.  * @version     1.0
  31.  */
  32. class kMyError
  33. {
  34.    private:
  35.       ULONG ulMyErrorNo;
  36.  
  37.    protected:
  38.       kMyError &setError(ULONG ulError);
  39.  
  40.    public:
  41.       kMyError();
  42.       kMyError(const kMyError &obj);
  43.       kMyError(ULONG ulError);
  44.       ULONG       getErrorNo() const;
  45.       const char *getDescription() const;
  46.  
  47.       enum enmError
  48.       {
  49.          unused, new_failed,
  50.          /* common main window stuff */
  51.          WinCreateWindow_failed_frame, WinCreateWindow_failed_client, user_cancel,
  52.          /* kMovie */
  53.          getPalette_failed, createPalette_failed, dive_failed, error_opening_movie,
  54.          /* kMovieFrame */
  55.          unsupported_bitcount, compressDiff_failed,
  56.          /* kMouseFrame */
  57.          getMousePos_failed,
  58.          /* Dos* functions */
  59.          DosCreateEventSem_failed,
  60.          /* Win* functions */
  61.          WinRegisterClass_failed,
  62.          /* stdio file functions */
  63.          ftell_failed, fread_failed, fopen_failed, fseek_failed, fwrite_failed,
  64.          /* other runtime library functions */
  65.          beginthread_failed, alloc_failed,
  66.          /* general read errors */
  67.          invalid_class, invalid_object, invalid_fileformat
  68.       };
  69. };
  70.  
  71.  
  72.  
  73. /**
  74.  * Dive error.
  75.  * @description Dive errors.
  76.  * @purpose     Error throwing in kDive and it's children.
  77.  * @assums      Nothing.
  78.  * @author      knut st. osmundsen
  79.  */
  80. class kDiveError
  81. {
  82.    private:
  83.       ULONG ulDiveError;
  84.  
  85.    protected:
  86.       kDiveError &setError(ULONG ulError);
  87.       kDiveError();
  88.  
  89.    public:
  90.       kDiveError(ULONG ulError);
  91.       kDiveError(const kDiveError &obj);
  92.       ULONG       getErrorNo() const;
  93.       const char *getDescription() const;
  94.  
  95.       enum enmDive
  96.       {
  97.          /* custom dive errors */
  98.          kDive_FirstError = 0xdeadbeefL,
  99.          alloc_mem_failed,
  100.          not_direct_access,
  101.  
  102.          /*DiveWnd*/
  103.          failed_to_create_framewnd,
  104.          failed_to_create_mutex,
  105.          failed_to_create_clientwnd,
  106.          queryRectangles_failed,
  107.          unsupported_colorencoding
  108.       };
  109. };
  110.  
  111.  
  112.  
  113. /**
  114.  * Win-api errors.
  115.  * @description Encapsulates win and gpi errors. Designed to very easily get a decent errordescription.
  116.  * @author      knut st. osmundsen
  117.  */
  118. class kWinError
  119. {
  120.    private:
  121.       ERRORID   errid;
  122.       PERRINFO  pErrInfo;
  123.       BOOL      fErrInfoDelete;
  124.       char     *psz;
  125.  
  126.       const char *getErrorInfoText(ULONG ulLevel = 0) const;
  127.  
  128.    protected:
  129.       kWinError  &setError(HAB hab = NULLHANDLE);
  130.  
  131.    public:
  132.       kWinError(HAB hab = NULLHANDLE, BOOL fInitiate = TRUE);
  133.       kWinError(const kWinError &obj);
  134.       ~kWinError();
  135.  
  136.       const char *getDescription() const;
  137.       ULONG       getErrorNo() const;
  138.       ULONG       getServerity() const;
  139. };
  140.  
  141.  
  142.  
  143.  
  144. /**
  145.  * Dos-api errors.
  146.  * @description Encapsulates standard OS/2 (Dos-api) errors. Designed to very easily get a decent errordescription.
  147.  * @author      knut st. osmundsen
  148.  */
  149. class kDosError
  150. {
  151.    private:
  152.       ULONG  ulRc;
  153.       PSZ    psz;
  154.  
  155.       VOID   prefetchMsg();
  156.  
  157.    protected:
  158.       kDosError &setError(ULONG ulRc);
  159.  
  160.    public:
  161.       kDosError();
  162.       kDosError(ULONG ulRc);
  163.       kDosError(const kDosError &obj);
  164.       ~kDosError();
  165.       const char *getDescription() const;
  166.       ULONG       getErrorNo() const;
  167. };
  168.  
  169.  
  170.  
  171. /**
  172.  * Collection of errors.
  173.  * @description Combines all k*Errors classes into one class.
  174.  * @author      knut st. osmundsen
  175.  */
  176. class kError: public kWinError, public kDiveError, public kMyError, public kDosError
  177. {
  178.    private:
  179.       unsigned long  ulErrorType;
  180.       char          *psz;
  181.  
  182.    public:
  183.       kError(unsigned long ulErrorNo, unsigned long ulErrorType = kError::my);
  184.       kError(const kError &obj);
  185.       ~kError();
  186.  
  187.       kError        &setError(unsigned long ulErrorNo, unsigned long ulErrorType = kError::my);
  188.  
  189.       const char    *getDescription() const;
  190.       unsigned long  getErrorNo() const;
  191.       unsigned long  getErrorType() const;
  192.  
  193.       BOOL           showError(const char *pszTitle) const;
  194.       const kError  &logError(const char *pszFunction, ULONG ulLine) const;
  195.       const kError  &logErrorStr(const char *pszUser, const char *pszFunction, ULONG ulLine) const;
  196.  
  197.       enum enmErrorType { my, dive, win, dos };
  198. };
  199.  
  200.  
  201.  
  202.  
  203. /*********/
  204. /* Macro */
  205. /*********/
  206. #define logError() logError(__FUNCTION__, __LINE__)
  207.  
  208. #endif
  209.  
  210.