Name

NSAssertionHandler — Mac OS X 10.0

Synopsis

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 condition—that is, assert that a condition must be true—and 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 ...

Get Cocoa in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.