O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required