Predefined Exceptions
Cocoa predefines a number of generic exception names to identify exceptions that you can handle in your own code or even raise and re-raise. You can also create and use custom exception names. The generic exception names are string constants defined in NSException.h
and documented in Foundation Constants Reference. These constants include the following:
NSGenericException
NSRangeException
NSInvalidArgumentException
NSInternalInconsistencyException
NSObjectInaccessibleException
NSObjectNotAvailableException
NSDestinationInvalidException
NSPortTimeoutException
NSInvalidSendPortException
NSInvalidReceivePortException
NSPortSendException
NSPortReceiveException
In addition to the generic exception names, some subsystems of Cocoa define their own exception names, such as NSInconsistentArchiveException
and NSFileHandleOperationException
. These are also documented in Foundation Constants Reference.
You can identify caught exceptions in your exception handler by comparing the exception's name with these predefined names. Then you can either handle the exception or, if it isn't one you are interested in, re-raise it. Note that all predefined exceptions begin with the prefix "NS", so you should avoid using the same prefix when creating new exception names.
Copyright © 2002, 2013 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2013-08-08