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

# NSError

Information about an error condition including a domain, a domain-specific error code, and application-specific information.

```
class NSError
```

## Overview

Objective-C methods can signal an error condition by returning an [`NSError`](/documentation/Foundation/NSError) object by reference, which provides additional information about the kind of error and any underlying cause, if one can be determined. An [`NSError`](/documentation/Foundation/NSError) object may also provide localized error descriptions suitable for display to the user in its user info dictionary. See [Error Handling Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorHandling/ErrorHandling.html#//apple_ref/doc/uid/TP40001806) for more information.

Methods in Foundation and other Cocoa frameworks most often produce errors in the Cocoa error domain ([`NSCocoaErrorDomain`](/documentation/Foundation/NSCocoaErrorDomain)); error codes for the Cocoa Error Domain are documented in the [Foundation Constants](/documentation/Foundation/foundation-constants). There are also predefined domains corresponding to Mach ([`NSMachErrorDomain`](/documentation/Foundation/NSMachErrorDomain)), POSIX ([`NSPOSIXErrorDomain`](/documentation/Foundation/NSPOSIXErrorDomain)), and Carbon ([`NSOSStatusErrorDomain`](/documentation/Foundation/NSOSStatusErrorDomain)) errors.

[`NSError`](/documentation/Foundation/NSError) is “toll-free bridged” with its Core Foundation counterpart, <doc://com.apple.documentation/documentation/CoreFoundation/CFError>. See [Toll-Free Bridging](https://developer.apple.com/library/archive/documentation/General/Conceptual/CocoaEncyclopedia/Toll-FreeBridgin/Toll-FreeBridgin.html#//apple_ref/doc/uid/TP40010810-CH2) for more information.

### Subclassing Notes

Applications may choose to create subclasses of `NSError`, for example, to provide better localized error strings by overriding [`localizedDescription`](/documentation/Foundation/NSError/localizedDescription).

## Topics

### Creating Error Objects

[`errorWithDomain:code:userInfo:`](/documentation/Foundation/NSError/errorWithDomain:code:userInfo:)

Creates and initializes an `NSError` object for a given domain and code with a given `userInfo` dictionary.

[`init(domain:code:userInfo:)`](/documentation/Foundation/NSError/init(domain:code:userInfo:))

Returns an `NSError` object initialized for a given domain and code with a given `userInfo` dictionary.

### Getting Error Properties

[`code`](/documentation/Foundation/NSError/code)

The error code.

[`domain`](/documentation/Foundation/NSError/domain)

A string containing the error domain.

[`userInfo`](/documentation/Foundation/NSError/userInfo)

The user info dictionary.

### Getting a Localized Error Description

[`localizedDescription`](/documentation/Foundation/NSError/localizedDescription)

A string containing the localized description of the error.

[`localizedRecoveryOptions`](/documentation/Foundation/NSError/localizedRecoveryOptions)

An array containing the localized titles of buttons appropriate for displaying in an alert panel.

[`localizedRecoverySuggestion`](/documentation/Foundation/NSError/localizedRecoverySuggestion)

A string containing the localized recovery suggestion for the error.

[`localizedFailureReason`](/documentation/Foundation/NSError/localizedFailureReason)

A string containing the localized explanation of the reason for the error.

### Providing Error User Info

[`setUserInfoValueProvider(forDomain:provider:)`](/documentation/Foundation/NSError/setUserInfoValueProvider(forDomain:provider:))

Specifies a block to call when the corresponding property is not present in the user info dictionary.

[`userInfoValueProvider(forDomain:)`](/documentation/Foundation/NSError/userInfoValueProvider(forDomain:))

Returns any user info provider specified for a given error domain.

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

These keys may exist in the user info dictionary.

[`NSError.UserInfoKey`](/documentation/Foundation/NSError/UserInfoKey)

These keys may exist in the user info dictionary.

### Getting the Error Recovery Attempter

[`recoveryAttempter`](/documentation/Foundation/NSError/recoveryAttempter)

The object in the user info dictionary corresponding to the [`NSRecoveryAttempterErrorKey`](/documentation/Foundation/NSRecoveryAttempterErrorKey) key.

[NSErrorRecoveryAttempting](/documentation/Foundation/nserrorrecoveryattempting)

A set of methods that provide options to recover from an error.

### Displaying a Help Anchor

[`helpAnchor`](/documentation/Foundation/NSError/helpAnchor)

A string to display in response to an alert panel help anchor button being pressed.

### Supporting Types

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

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

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

### Error Domains

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

Cocoa errors

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

POSIX/BSD errors

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

Mac OS 9/Carbon errors

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

Mach errors

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

URL loading system errors

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

The error domain used by `NSError` when reporting SOCKS errors.

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

The error domain used by `NSError` when reporting SSL errors.

### Error Codes

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

Describes errors within the Cocoa error domain.

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

Describes an error in the Mach error domain.

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

Describes an error in the POSIX error domain.

[NSError Codes](/documentation/Foundation/1448136-nserror-codes)

Error codes in the Cocoa error domain.

  <doc:1448136-nserror_codes>



---

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)