Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Handling Errors
Mostly in the interest of code simplification,
Core Foundation functions do not follow the Mac OS OSErr
convention
for error reporting. However, if you rigorously test your program
with the debug version of the Core Foundation library (or framework),
then the possibilities for error are much reduced.
Yet there can be occasions when you want to test whether a function succeeds in its intended purpose and proceed conditionally from there. By a common-sense interpretation of returned values (and sometimes by a quick check of the reference documentation), you can usually determine the reason for failure, as in these examples:
If functions that are supposed to create or copy objects return
NULL
, the probable reason is an error in the allocation of memory.If functions that are supposed to return an element from a index-based collection (that is, a CFArray) return an indeterminate value, the probable cause is an index parameter that is out of bounds.
If a function is supposed to return a CFArray of values, each element of which satisfies some condition specified by the function, and an empty CFArray is returned, then no object has satisfied that condition.
Some Core Foundation functions return a value of type Boolean
or
an enum
constant or some
other explicitly typed indication of the reason for an outcome.
Consult the Core Foundation reference documentation for an explanation
of these return values.
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-17