home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / lang / skel_azt.sha / errmsg.c < prev    next >
C/C++ Source or Header  |  1986-07-08  |  3KB  |  94 lines

  1.  
  2. /*
  3.  *    errmsg.c -- report an error message
  4.  *    This routine and the way it is used by drawgraf and filemenu are
  5.  *    meant to suggest that Macintosh applications should have better
  6.  *    error reporting than Inside Macintosh suggests.  Perhaps even a
  7.  *    failure of "GetString" should be reported, but the (perhaps
  8.  *    mistaken) assumption is made that only a failure of the developer
  9.  *    to include the correct resources or inappropriate surgery via
  10.  *    ResEdit would cause GetString to fail.  Inside Macintosh suggests
  11.  *    the "alert" mechanism to report errors to the user, and the alert
  12.  *    method may be appropriate if a user is trying to execute a command
  13.  *    (menu item) when no appropriate object is selected.  But some
  14.  *    behavior of commercial Macintosh programs is just plain
  15.  *    inexcusable.  For example, MacDraw (maybe the problem is really
  16.  *    the print driver) will not print when the disk is too full for
  17.  *    the "spool" file, but it provides no mechanism to use another disk,
  18.  *    and doesn't even report why it doesn't print.  For another example,
  19.  *    the DS (newly claimed to mean "dire straits") alert dialog and
  20.  *    most dialogs that report file manager errors only report an error
  21.  *    number, with no textual explanation or the error.  The owner's
  22.  *    manual that comes with a Macintosh does not even list what the
  23.  *    error numbers mean!
  24.  *    So let's reach for a higher plane of excellence, and let the user
  25.  *    know not only that an error occurred, but what the error was.  The
  26.  *    next step may be to put some suggestions about what to do about
  27.  *    the error in the manual, or in the program.  Also consider having
  28.  *    features in your program that allow a mechanism to recover from
  29.  *    possible errors.
  30.  */
  31.  
  32. #include <osutil.h>
  33. #include <packages.h>
  34. #include <resource.h>
  35. #include <syserr.h>
  36. #include <toolutil.h>
  37.  
  38. errmsg(opstrid, e)
  39. char    opstrid;    /* ID of the string resource that will begin
  40.                      *    the message
  41.                      */
  42. OSErr    e;            /* number printed in the message, and used to find
  43.                      * an error message that will end the message
  44.                      * if 0, the message is only the "opstrid" part
  45.                      */
  46. {
  47.     char    emstr[255];
  48.     Handle    errstrh;
  49.     char    estr[10];
  50.     Handle    opstrh;
  51.  
  52.     SysBeep(10);
  53.     opstrh = GetString(opstrid);
  54.     if (opstrh) {
  55.         ptoc(*opstrh);
  56.         strcpy(emstr, *opstrh);
  57.         if (e) {
  58.             strcat(emstr, " ");
  59.             NumToString((long)e, estr);
  60.             ptoc(estr);
  61.             strcat(emstr, estr);
  62.             errstrh = GetString(20 - e);
  63.             if (!errstrh)
  64.                 errstrh = GetString(13);
  65.             if (errstrh) {
  66.                 ptoc(*errstrh);
  67.                 strcat(emstr, "\r");
  68.                 strcat(emstr, *errstrh);
  69.                 ReleaseResource(errstrh);
  70.                 DisposHandle(errstrh);
  71.             };
  72.         };
  73.         ReleaseResource(opstrh);
  74.         DisposHandle(opstrh);
  75.     }
  76.     else {
  77.         strcpy(emstr, "can't get error message resource for error ");
  78.         NumToString((long)e, estr);
  79.         ptoc(estr);
  80.         strcat(emstr, estr);
  81.     };
  82.     /*
  83.      * NOTE:  if the dialog item for the error message static text
  84.      *        was slightly too small for the text of the message, the
  85.      *        clipping done was not healthy for the rest of the
  86.      *        system -- it would clobber the stack after the OK box
  87.      *        was clicked in modaldialog.  (Just another of those
  88.      *        little things to watch out for.)
  89.      */
  90.  
  91.     ctop(emstr);
  92.     report(emstr);
  93. } /* end of errmsg() */
  94.