<!--
{
  "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/NSException",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSException"
  },
  "title" : "NSException"
}
-->

# NSException

An object that represents a special condition that interrupts the normal flow of program execution.

```
class NSException
```

## Overview

Use [`NSException`](/documentation/Foundation/NSException) to implement exception handling. An exception is a special condition that interrupts the normal flow of program execution. Each application can interrupt the program for different reasons. For example, one application might interpret saving a file in a directory that is write-protected as an exception. In this sense, the exception is equivalent to an error. Another application might interpret the user’s key-press (for example, Control-C) as an exception: an indication that a long-running process should abort.

## Topics

### Creating and Raising an NSException Object

[`exceptionWithName:reason:userInfo:`](/documentation/Foundation/NSException/exceptionWithName:reason:userInfo:)

Creates and returns an exception object .

[`raise:format:`](/documentation/Foundation/NSException/raise:format:)

A convenience method that creates and raises an exception.

[`raise(_:format:arguments:)`](/documentation/Foundation/NSException/raise(_:format:arguments:))

Creates and raises an exception with the specified name, reason, and arguments.

[`init(name:reason:userInfo:)`](/documentation/Foundation/NSException/init(name:reason:userInfo:))

Initializes and returns a newly allocated exception object.

[`raise()`](/documentation/Foundation/NSException/raise())

Raises the receiver, causing program flow to jump to the local exception handler.

### Querying an NSException Object

[`name`](/documentation/Foundation/NSException/name-swift.property)

A string used to uniquely identify the receiver.

[`reason`](/documentation/Foundation/NSException/reason-swift.property)

A string containing a “human-readable” reason for the receiver.

[`userInfo`](/documentation/Foundation/NSException/userInfo-swift.property)

A dictionary containing application-specific data pertaining to the receiver.

### Getting Exception Stack Frames

[`callStackReturnAddresses`](/documentation/Foundation/NSException/callStackReturnAddresses)

The call return addresses related to a raised exception.

[`callStackSymbols`](/documentation/Foundation/NSException/callStackSymbols)

An array containing the current call stack symbols.

### Related Types

[`NSUncaughtExceptionHandler`](/documentation/Foundation/NSUncaughtExceptionHandler)

The type for uncaught exception handler functions.

[`NSExceptionName`](/documentation/Foundation/NSExceptionName)

### Functions

[`NSGetUncaughtExceptionHandler()`](/documentation/Foundation/NSGetUncaughtExceptionHandler())

Returns the top-level error handler.

[`NSSetUncaughtExceptionHandler(_:)`](/documentation/Foundation/NSSetUncaughtExceptionHandler(_:))

Changes the top-level error handler.

### Legacy Macros

[`NS_DURING`](/documentation/Foundation/NS_DURING)

Marks the start of the exception-handling domain.

[`NS_ENDHANDLER`](/documentation/Foundation/NS_ENDHANDLER)

Marks the end of the local event handler.

[`NS_HANDLER`](/documentation/Foundation/NS_HANDLER)

Marks the end of the exception-handling domain and the start of the local exception handler.

[`NS_VALUERETURN`](/documentation/Foundation/NS_VALUERETURN)

Permits program control to exit from an exception-handling domain with a value of a specified type.

[`NS_VOIDRETURN`](/documentation/Foundation/NS_VOIDRETURN)

Permits program control to exit from an exception-handling domain.



---

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)