<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSAssertionHandler",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSAssertionHandler"
  },
  "title" : "NSAssertionHandler"
}
-->

# NSAssertionHandler

An object that logs an assertion to the console.

```
class NSAssertionHandler
```

## 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:`](/documentation/Foundation/NSAssertionHandler/handleFailureInMethod:object:file:lineNumber:description:) and [`handleFailureInFunction:file:lineNumber:description:`](/documentation/Foundation/NSAssertionHandler/handleFailureInFunction:file:lineNumber:description:) messages respectively to the current assertion handler. The assertion handler for the current thread is obtained using the [`current`](/documentation/Foundation/NSAssertionHandler/current) class method. See <doc:nsassertionhandlerkey> if you need to customize the behavior of [`NSAssertionHandler`](/documentation/Foundation/NSAssertionHandler).

## Topics

### Handling Assertion Failures

[`currentHandler`](/documentation/Foundation/NSAssertionHandler/current)

Returns the `NSAssertionHandler` object associated with the current thread.

[`-  handleFailureInFunction:file:lineNumber:description:`](/documentation/Foundation/NSAssertionHandler/handleFailureInFunction:file:lineNumber:description:)

[`-  handleFailureInMethod:object:file:lineNumber:description:`](/documentation/Foundation/NSAssertionHandler/handleFailureInMethod:object:file:lineNumber:description:)

### Constants

The string constants for exceptions are listed and described in the Exceptions section of the [Foundation Constants](/documentation/Foundation/foundation-constants)

This document defines constants in the Foundation framework that are not associated with a particular class..

  <doc:nsassertionhandlerkey>

## Relationships

### Conforms To

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`Hashable`](/documentation/Swift/Hashable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)