<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFError",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@T@CFErrorRef"
  },
  "title" : "CFError"
}
-->

# CFError

```
class CFError
```

## Overview

A CFError object encapsulates more rich and extensible error information than is possible using only an error code or error string. The core attributes of a CFError object are an error domain (represented by a string), a domain-specific error code, and a “user info” dictionary containing application-specific information. Errors are required to have a domain and an error code within that domain. Several well-known domains are defined corresponding to Mach, POSIX, and OSStatus errors.

The optional “user info” dictionary may provide additional information that might be useful for the interpretation and reporting of the error, including a human-readable description for the error. The “user info” dictionary sometimes includes another CFError object that represents an error in a subsystem underlying the error represented by the containing CFError object. This underlying error object may provide more specific information about the cause of the error.

In general, a method should signal an error condition by returning, for example, `false` or `NULL` rather than by the simple presence of an error object. The method can then optionally return an CFError object by reference, in order to further describe the error.

CFError is toll-free bridged to <doc://com.apple.documentation/documentation/Foundation/NSError> in the Foundation framework—for more details on toll-free bridging, see [Toll-Free Bridged Types](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html#//apple_ref/doc/uid/TP40010677). `NSError` has some additional guidelines that make it easy to report errors automatically to users and attempt to recover from them. 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 on `NSError` programming guidelines.

## Topics

### Creating a CFError

[`CFErrorCreate(_:_:_:_:)`](/documentation/CoreFoundation/CFErrorCreate(_:_:_:_:))

Creates a new CFError object.

[`CFErrorCreateWithUserInfoKeysAndValues(_:_:_:_:_:_:)`](/documentation/CoreFoundation/CFErrorCreateWithUserInfoKeysAndValues(_:_:_:_:_:_:))

Creates a new CFError object using given keys and values to create the user info dictionary.

### Getting Information About an Error

[`CFErrorGetDomain(_:)`](/documentation/CoreFoundation/CFErrorGetDomain(_:))

Returns the error domain for a given CFError.

[`CFErrorGetCode(_:)`](/documentation/CoreFoundation/CFErrorGetCode(_:))

Returns the error code for a given CFError.

[`CFErrorCopyUserInfo(_:)`](/documentation/CoreFoundation/CFErrorCopyUserInfo(_:))

Returns the user info dictionary for a given CFError.

[`CFErrorCopyDescription(_:)`](/documentation/CoreFoundation/CFErrorCopyDescription(_:))

Returns a human-presentable description for a given error.

[`CFErrorCopyFailureReason(_:)`](/documentation/CoreFoundation/CFErrorCopyFailureReason(_:))

Returns a human-presentable failure reason for a given error.

[`CFErrorCopyRecoverySuggestion(_:)`](/documentation/CoreFoundation/CFErrorCopyRecoverySuggestion(_:))

Returns a human presentable recovery suggestion for a given error.

### Getting the CFError Type ID

[`CFErrorGetTypeID()`](/documentation/CoreFoundation/CFErrorGetTypeID())

Returns the type identifier for the CFError opaque type.

### Constants

[Error domains](/documentation/CoreFoundation/error-domains)

These constants define domains for CFError objects.

[Keys for the user info dictionary](/documentation/CoreFoundation/keys-for-the-user-info-dictionary)

Keys in the `userInfo` dictionary.

## See Also

  [Error Handling Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorHandling/ErrorHandling.html#//apple_ref/doc/uid/TP40001806)



---

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)