| ||
Home | Modules | Examples |
NULL
, which is always interpreted as kCCMIONoErr
, should be passed to the function and the return value checked for success. If the error pointer were passed then an error would be recorded and no succeeding function would execute, even though they should.Dataflow error handling allows the API user to write code that opens a file, does some reading or writing, and then closes it, without checking for errors until the end. The API guarantees that any return parameters of the function will be usable (i.e not crash), unless otherwise documented, and that, should an error occur early on, all memory will properly be deallocated.
There are several things to keep in mind when using errors:
CCMIOError err = kCCMIONoErr;
unless it is being assigned as a result of an API call (e.g.CCMIOOpenFile
).
kCCMIONoErr
should always have a value of 0 (zero), it is preferable to compare errors to kCCMIONoErr
to avoid confusion, since while !err
is a correct test for an error, !CCMIOOpenFile
reads like it checks for the failure of the function, but in reality returns true only if there was not an error. Thusif (CCMIOOpenFile(...) != kCCMIONoErr)should be the canonical test.
kCCMIONoNodeErr
): i = 0;
while (CCMIONextEntity(NULL, parentID, kCCMIOField, &i, &child) == kCCMIONoErr)
... do stuff ...