home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / p / pc2.zip / SOURCE.ZIP / SOURCE / ERROR.C < prev    next >
Text File  |  1993-03-09  |  12KB  |  196 lines

  1. /***********************************************************************\
  2.  *                               Error.c                               *
  3.  *                 Copyright (C) by Stangl Roman, 1992                 *
  4.  * This Code may be freely distributed, provided the Copyright isn't   *
  5.  * removed.                                                            *
  6.  *                                                                     *
  7.  * Requires: Error.c    The routing General_Error                      *
  8.  *           Error.h    The include-file that defines the macros       *
  9.  *                      GEN_ERR, DOS_ERR, USR_ERR                      *
  10.  *                                                                     *
  11.  * Error is a general errorhandler for OS/2 2.0 PM programmer to easy  *
  12.  * program development. The routine General_Error displays:            *
  13.  *      ErrModule       The module containing the error                *
  14.  *      ErrLine         The sourcecode line, that contains the error   *
  15.  *      Error           The error returned by an OS/2 API              *
  16.  * The routine requires the following parameters passed:               *
  17.  *      HAB hab         The anchor block handle                        *
  18.  *      HWND hwndFrame  The windowhandle of the frame window           *
  19.  *      HWND hwndClient The windowhandle of the client window          *
  20.  *      PSZ ErrModule   The pointer to the name of the module _FILE_   *
  21.  *      LONG ErrLine    The pointer to the sourcecodeline __LINE__     *
  22.  *                                                                     *
  23.  * This routine displays a message box, with Abort, Retry, Ignore      *
  24.  * buttons. If Abort is selected, and hwndFrame<>NULL, then post a     *
  25.  * WM_QUIT message to hwndFrame, else exit to OS/2 via exit().         *
  26.  *                                                                     *
  27.  * The routine Dos_Error displays:                                     *
  28.  *      ErrModule       The module containing the error                *
  29.  *      ErrLine         The sourcecode line, that contains the error   *
  30.  *      Error           The error returned by an OS/2 API              *
  31.  * The routine requires the following parameters passed:               *
  32.  *      ReturnCode      The returncode of an os/2 API                  *
  33.  *      HWND hwndFrame  The windowhandle of the frame window           *
  34.  *      HWND hwndClient The windowhandle of the client window          *
  35.  *      PSZ ErrModule   The pointer to the name of the module _FILE_   *
  36.  *      LONG ErrLine    The pointer to the sourcecodeline __LINE__     *
  37.  *                                                                     *
  38.  * This routine displays a message box, with Abort, Retry, Ignore      *
  39.  * buttons. If Abort is selected, and hwndFrame<>NULL, then post a     *
  40.  * WM_QUIT message to hwndFrame, else exit to OS/2 via exit().         *
  41.  *                                                                     *
  42.  * The routine User_Error displays:                                    *
  43.  *      ErrModule       The module containing the error                *
  44.  *      ErrLine         The sourcecode line, that contains the error   *
  45.  *      Error           The error indicated by the user                *
  46.  * The routine requires the following parameters passed:               *
  47.  *      PSZ ErrorCode   The errorcode of the user                      *
  48.  *      HWND hwndFrame  The windowhandle of the frame window           *
  49.  *      HWND hwndClient The windowhandle of the client window          *
  50.  *      PSZ ErrModule   The pointer to the name of the module _FILE_   *
  51.  *      LONG ErrLine    The pointer to the sourcecodeline __LINE__     *
  52.  *                                                                     *
  53.  * This routine displays a message box, with Abort, Retry, Ignore      *
  54.  * buttons. If Abort is selected, and hwndFrame<>NULL, then post a     *
  55.  * WM_QUIT message to hwndFrame, else exit to OS/2 via exit().         *
  56.  *                                                                     *
  57. \***********************************************************************/
  58.  
  59. static char RCSID[]="@(#) $Header: Error.c/Error.h Version 1.20 03,1993 $ (LBL)";
  60.  
  61. #include        "error.h"               /* Include headerfile */
  62.  
  63. void General_Error(HAB hab,HWND hwndFrame,HWND hwndClient,PSZ ErrModule,LONG ErrLine)
  64. {
  65. static PERRINFO         pErrInfoBlk;    /* Pointer to ERRINFO structure that is filled
  66.                                            by WinGetErrorInfo */
  67. static PSZ              pszOffset;      /* Pointer to the current error message returned
  68.                                            by WinGetErrorInfo */
  69. static unsigned char    ErrBuffer[512]; /* The whole error message that is displayed to
  70.                                            the user via WinMessageBox */
  71.  
  72. sprintf(ErrBuffer,"Error found in Module: %s\nLinenumber in Sourcecode: %d\n"\
  73.     "Error reported by OS/2: ",ErrModule,ErrLine);
  74.                                         /* Get last error for the current thread. We loop
  75.                                            until no more error is found, although errors
  76.                                            arn't stacked (but things may change) */
  77. while((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
  78.     {
  79.     DosBeep(1000,200);                  /* Signal to user via speaker */
  80.     DosBeep(300,200);
  81.     DosBeep(1000,200);
  82.                                         /* Find offset in array of message offsets */
  83.     pszOffset = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
  84.                                         /* Address error message in array of messages and 
  85.                                            append error message to source code linenumber */
  86.     strcat(ErrBuffer,(((PSZ)pErrInfoBlk) + *((PSHORT)pszOffset)));
  87.     if((WinMessageBox(HWND_DESKTOP,     /* Parent window is DESKTOP */
  88.             HWND_DESKTOP,               /* Owner window is DESKTOP */
  89.             (PSZ)ErrBuffer,             /* General_Error message */
  90.                                         /* Title bar message */
  91.             "General Error Message Information",
  92.             GEN_ERR_MSGBOXID,           /* Message identifier */
  93.                                         /* Buttons Abort, Retry, Ignore */
  94.             MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_DEFBUTTON3)
  95.         )==MBID_ABORT)                  /* If user selected Abort, then close application */
  96.             if(hwndFrame==(HWND) NULL)  /* If no frame window handle available, then exit
  97.                                            OS/2 via exit, else post a WM_QUIT message */
  98.                 exit(1);
  99.             else
  100.                 WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
  101.     WinFreeErrorInfo(pErrInfoBlk);      /* Free resource segment */
  102.     }
  103. }
  104.  
  105. void Dos_Error(ULONG Error,HWND hwndFrame,HWND hwndClient,PSZ ErrModule,LONG ErrLine)
  106. {
  107. static unsigned char    MsgBuffer[512]; /* The whole error message that is displayed to
  108.                                            the user via WinMessageBox */
  109. static ULONG            Class;          /* Error class */
  110. static ULONG            Action;         /* Error action */
  111. static ULONG            Locus;          /* Error location */
  112.  
  113. static unsigned char    *Err_Class[]={"Out of ressource",
  114.                                       "Temporary situation",
  115.                                       "Authorization failed",
  116.                                       "Internal error",
  117.                                       "Device hardware failure",
  118.                                       "System failure",
  119.                                       "Probable application failure",
  120.                                       "Item not located",
  121.                                       "Bad format for call/data",
  122.                                       "Resource or data locked",
  123.                                       "Incorrect media, CRC check",
  124.                                       "Action already taken or done",
  125.                                       "Unclassified",
  126.                                       "Cannot perform requested action",
  127.                                       "Timeout",
  128.                                       "Error in file \"Error.c\""};
  129. static unsigned char    *Err_Action[]={"Retry immediately",
  130.                                        "Delay and retry",
  131.                                        "Bad user input - get new values",
  132.                                        "Terminate in an orderly manner",
  133.                                        "Terminate immediately",
  134.                                        "Ignore error",
  135.                                        "Retry after user intervention",
  136.                                        "Error in file \"Error.c\""};
  137. static unsigned char    *Err_Locus[]={"Unknown",
  138.                                       "Random access device such as a disk",
  139.                                       "Network",
  140.                                       "Serial device",
  141.                                       "Memory",
  142.                                       "Error in file \"Error.c\""};
  143.  
  144. if(Error!=0)
  145. {
  146.     DosBeep(1000,200);                  /* Signal to user via speaker */
  147.     DosBeep(300,200);
  148.     DosBeep(1000,200);
  149.     DosErrClass(Error,&Class,&Action,&Locus);
  150.     sprintf(MsgBuffer,"Error found in Module: %s\nLinenumber in Sourcecode: %d\n"\
  151.         "Error reported by OS/2: %d\nClass: %s\nAction: %s\n"\
  152.         "Location: %s\n",ErrModule,ErrLine,Error,Err_Class[Class-1],\
  153.         Err_Action[Action-1],Err_Locus[Locus-1]);
  154.     if((WinMessageBox(HWND_DESKTOP,     /* Parent window is DESKTOP */
  155.             HWND_DESKTOP,               /* Owner window is DESKTOP */
  156.             (PSZ)MsgBuffer,             /* DOS API error message */
  157.                                         /* Title bar message */
  158.             "OS/2 DosApi Error Message Information",
  159.             GEN_ERR_MSGBOXID,           /* Message identifier */
  160.                                         /* Buttons Abort, Retry, Ignore */
  161.             MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_DEFBUTTON3)
  162.         )==MBID_ABORT)
  163.             if(hwndFrame==(HWND) NULL)  /* If no frame window handle available, then exit
  164.                                            OS/2 via exit, else post a WM_QUIT message */
  165.                 exit(1);
  166.             else
  167.                 WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
  168. }
  169. }
  170.  
  171. void User_Error(PSZ Error,HWND hwndFrame,HWND hwndClient,PSZ ErrModule,LONG ErrLine)
  172. {
  173. static unsigned char    MsgBuffer[512]; /* The whole error message that is displayed to
  174.                                            the user via WinMessageBox */
  175.  
  176. DosBeep(1000,200);                      /* Signal to user via speaker */
  177. DosBeep(300,200);
  178. DosBeep(1000,200);
  179. sprintf(MsgBuffer,"Error found in Module: %s\nLinenumber in Sourcecode: %d\n"\
  180.     "%s\n",ErrModule,ErrLine,Error);
  181. if((WinMessageBox(HWND_DESKTOP,         /* Parent window is DESKTOP */
  182.         HWND_DESKTOP,                   /* Owner window is DESKTOP */
  183.         (PSZ)MsgBuffer,                 /* User indicated error message */
  184.                                         /* Title bar message */
  185.         "User indicated Error Message Information",
  186.         GEN_ERR_MSGBOXID,               /* Message identifier */
  187.                                         /* Buttons Abort, Retry, Ignore */
  188.         MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION | MB_DEFBUTTON3)
  189.     )==MBID_ABORT)
  190.         if(hwndFrame==(HWND) NULL)      /* If no frame window handle available, then exit
  191.                                            OS/2 via exit, else post a WM_QUIT message */
  192.             exit(1);
  193.         else
  194.             WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
  195. }
  196.