Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: More Macintosh Toolbox /
Chapter 1 - Resource Manager / Resource Manager Reference
Resource Manager Routines / Checking for Errors


ResError

After calling a Resource Manager routine, you can use the ResError function to determine whether an error occurred and, if so, what it was.

FUNCTION ResError: Integer;
DESCRIPTION
The ResError function reads the value stored in the system global variable ResErr and returns an integer result code identifying errors, if any, that occurred. If no error occurred, ResError returns noErr. If an error occurs at the Resource Manager level, ResError returns one of the integer result codes listed in this section. If an error occurs at the Operating System level, ResError returns an Operating System result code, such as the Memory Manager error memFullErr or the File Manager error ioErr.

Resource Manager procedures do not report error information directly. Instead, after calling a Resource Manager procedure, your application should call the ResError function to determine whether an error occurred.

Resource Manager functions usually return NIL or -1 as the function result when there's an error. For Resource Manager functions that return -1, your application can call the ResError function to determine the specific error that occurred. For Resource Manager functions that return handles, your application should always check whether the value of the returned handle is NIL. If it is, your application can use ResError to obtain specific information about the nature of the error. Note, however, that in some cases ResError returns noErr even though the value of the returned handle is NIL.

IMPORTANT
In certain cases, the ResError function returns noErr even though a Resource Manager routine was unable to perform the requested operation. See the individual routine descriptions for details about the circumstances under which this happens.
Only those result codes dealing specifically with resources are listed in this section. See the description of each Resource Manager routine for a list of errors specific to that routine and that the ResError function returns.

ASSEMBLY-LANGUAGE INFORMATION
The global variable ResErr stores the current value of ResError, that is, the result code of the most recently performed Resource Manager operation. In addition, you can specify an application-defined procedure to be called whenever an error occurs. To do this, store the address of the procedure in the global variable ResErrProc. The value of the ResErrProc global variable is usually 0. Before returning a result code other than noErr, the ResError function puts that result in register D0 and calls the procedure identified by the ResErrProc global variable.

If you use ResErrProc to detect resource errors, you will get unexpected calls to your application-defined procedure if you call GetMenu. The Menu Manager routine GetMenu makes a call to GetResInfo, requesting resource information about
'MDEF' 0. Unfortunately, because ROMMapInsert is set to FALSE, this call fails, setting ResErr to -192 (resNotFound). This, in turn, causes a call to your application-defined procedure, even though the GetMenu routine has worked correctly.

To avoid this problem, follow these steps when you call GetMenu if you are using ResErrProc:

  1. Save the address of your application-defined procedure.
  2. Clear ResErrProc.
  3. Call GetResource for the menu resource you want to get.
  4. Check whether GetResource returns a handle whose value is NIL; if so, process the error in whatever way is appropriate for your application.
  5. Call GetMenu.
  6. When you are finished calling GetMenu, restore the previous value of ResErrProc.

RESULT CODES
noErr0No error
resNotFound-192Resource not found
resFNotFound-193Resource file not found
addResFailed-194AddResource procedure failed
rmvResFailed-196RemoveResource procedure failed
resAttrErr-198Attribute inconsistent with operation
mapReadErr-199Map inconsistent with operation

Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996