NSAssertionHandler Mac OS X 10.0

The NSAssertionHandler class is responsible for assertions that are created using the Foundation framework assertion macros. Every thread has its own assertion handler object that is obtained through the class method currentHandler. NSAssertionHandler provides the methods handleFailureInMethod:object:file:lineNumber:description: and handleFailureInFunction:file:lineNumber:description: to log error messages in response to assertion failures within methods and functions, respectively.

The assertion macros allow the user to check for a given conditionthat is, assert that a condition must be trueand if the condition is false, a string is passed to the assertion handler, and the handler is notified of the failed assertion. When the assertion handler receives notification of a failed assertion it will print an error message that includes the user-specified string, as well as the class and method names where the assertion failure occurred. Additionally, an NSInternalInconsistencyException is raised. If this exception is not handled by the application, the application will exit.

The Foundation framework defines six assertion macros that can be used within an Objective-C method (NSAssert, NSAssert1, NSAssert2, etc.) and six macros that may be used within a C function (NSCAssert, NSCAssert1, NSCAssert2, etc.). Each of these macros takes a condition that will be asserted, and a string that will be printed as part of the error message. The numbered macros allow the client to pass additional parameters for printf- style formatted strings.


@interface NSAssertionHandler : NSObject
 // Class Methods
   + (NSAssertionHandler *)currentHandler;
 // Instance Methods
   - (void)handleFailureInFunction:(NSString *)functionName file:(NSString *)fileName lineNumber:(int)line
        description:(NSString *)format,...;
   - (void)handleFailureInMethod:(SEL)selector object:(id)object file:(NSString *)fileName
        lineNumber:(int)line description:(NSString *)format,...;

    Part II: API Quick Reference
    Chapter 13. Foundation Classes