home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * errmsg.c -- report an error message
- * This routine and the way it is used by drawgraf and filemenu are
- * meant to suggest that Macintosh applications should have better
- * error reporting than Inside Macintosh suggests. Perhaps even a
- * failure of "GetString" should be reported, but the (perhaps
- * mistaken) assumption is made that only a failure of the developer
- * to include the correct resources or inappropriate surgery via
- * ResEdit would cause GetString to fail. Inside Macintosh suggests
- * the "alert" mechanism to report errors to the user, and the alert
- * method may be appropriate if a user is trying to execute a command
- * (menu item) when no appropriate object is selected. But some
- * behavior of commercial Macintosh programs is just plain
- * inexcusable. For example, MacDraw (maybe the problem is really
- * the print driver) will not print when the disk is too full for
- * the "spool" file, but it provides no mechanism to use another disk,
- * and doesn't even report why it doesn't print. For another example,
- * the DS (newly claimed to mean "dire straits") alert dialog and
- * most dialogs that report file manager errors only report an error
- * number, with no textual explanation or the error. The owner's
- * manual that comes with a Macintosh does not even list what the
- * error numbers mean!
- * So let's reach for a higher plane of excellence, and let the user
- * know not only that an error occurred, but what the error was. The
- * next step may be to put some suggestions about what to do about
- * the error in the manual, or in the program. Also consider having
- * features in your program that allow a mechanism to recover from
- * possible errors.
- */
-
- #include <osutil.h>
- #include <packages.h>
- #include <resource.h>
- #include <syserr.h>
- #include <toolutil.h>
-
- errmsg(opstrid, e)
- char opstrid; /* ID of the string resource that will begin
- * the message
- */
- OSErr e; /* number printed in the message, and used to find
- * an error message that will end the message
- * if 0, the message is only the "opstrid" part
- */
- {
- char emstr[255];
- Handle errstrh;
- char estr[10];
- Handle opstrh;
-
- SysBeep(10);
- opstrh = GetString(opstrid);
- if (opstrh) {
- ptoc(*opstrh);
- strcpy(emstr, *opstrh);
- if (e) {
- strcat(emstr, " ");
- NumToString((long)e, estr);
- ptoc(estr);
- strcat(emstr, estr);
- errstrh = GetString(20 - e);
- if (!errstrh)
- errstrh = GetString(13);
- if (errstrh) {
- ptoc(*errstrh);
- strcat(emstr, "\r");
- strcat(emstr, *errstrh);
- ReleaseResource(errstrh);
- DisposHandle(errstrh);
- };
- };
- ReleaseResource(opstrh);
- DisposHandle(opstrh);
- }
- else {
- strcpy(emstr, "can't get error message resource for error ");
- NumToString((long)e, estr);
- ptoc(estr);
- strcat(emstr, estr);
- };
- /*
- * NOTE: if the dialog item for the error message static text
- * was slightly too small for the text of the message, the
- * clipping done was not healthy for the rest of the
- * system -- it would clobber the stack after the OK box
- * was clicked in modaldialog. (Just another of those
- * little things to watch out for.)
- */
-
- ctop(emstr);
- report(emstr);
- } /* end of errmsg() */
-