Class

NSAssertionHandler

An object that logs an assertion to the console.

Declaration

@interface NSAssertionHandler : NSObject

Overview

NSAssertionHandler objects are automatically created to handle false assertions. Assertion macros, such as NSAssert and NSCAssert, are used to evaluate a condition, and if the condition evaluates to false, the macros pass a string to an NSAssertionHandler object describing the failure. Each thread has its own NSAssertionHandler object. When invoked, an assertion handler prints an error message that includes the method and class (or function) containing the assertion and raises an NSInternalInconsistencyException.

You create assertions only using the assertion macros—you rarely need to invoke NSAssertionHandler methods directly. The macros for use inside methods and functions send handleFailureInMethod:object:file:lineNumber:description: and handleFailureInFunction:file:lineNumber:description: messages respectively to the current assertion handler. The assertion handler for the current thread is obtained using the currentHandler class method. See NSAssertionHandlerKey if you need to customize the behavior of NSAssertionHandler.

Topics

Handling Assertion Failures

currentHandler

Returns the NSAssertionHandler object associated with the current thread.

- handleFailureInFunction:file:lineNumber:description:

Logs (using NSLog) an error message that includes the name of the function, the name of the file, and the line number.

- handleFailureInMethod:object:file:lineNumber:description:

Logs (using NSLog) an error message that includes the name of the method that failed, the class name of the object, the name of the source file, and the line number.

Constants

The string constants for exceptions are listed and described in the Exceptions section of the Foundation Constants.

NSAssertionHandlerKey

This constant refers to a key in the thread dictionary of the per-thread assertion handler object

Relationships

Inherits From

See Also

Assertions

NSAssert

Generates an assertion if a given condition is false.

NSAssert1

Generates an assertion if a given condition is false.

NSAssert2

Generates an assertion if a given condition is false.

NSAssert3

Generates an assertion if a given condition is false.

NSAssert4

Generates an assertion if a given condition is false.

NSAssert5

Generates an assertion if a given condition is false.

NSCAssert

Generates an assertion if the given condition is false.

NSCAssert1

Generates an assertion if a given condition is false.

NSCAssert2

Generates an assertion if a given condition is false.

NSCAssert3

Generates an assertion if a given condition is false.

NSCAssert4

Generates an assertion if a given condition is false.

NSCAssert5

Generates an assertion if a given condition is false.

NSCParameterAssert

Evaluates the specified parameter.

NSParameterAssert

Validates the specified parameter.