<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSCoder/DecodingFailurePolicy-swift.enum/setErrorAndReturn",
  "metadataVersion" : "0.1.0",
  "role" : "Case",
  "symbol" : {
    "kind" : "Case",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:@E@NSDecodingFailurePolicy@NSDecodingFailurePolicySetErrorAndReturn"
  },
  "title" : "NSCoder.DecodingFailurePolicy.setErrorAndReturn"
}
-->

# NSCoder.DecodingFailurePolicy.setErrorAndReturn

A failure policy that directs the coder to capture the failure as an error object.

```
case setErrorAndReturn
```

## Discussion

On decode failure, the [`NSCoder`](/documentation/Foundation/NSCoder) will capture the failure as an [`NSError`](/documentation/Foundation/NSError), and prevent further decodes (by returning `0` / `nil` equivalent as appropriate).

Use this policy if you know that all encoded objects use [`failWithError(_:)`](/documentation/Foundation/NSCoder/failWithError(_:)) to communicate decode failures and don’t raise exceptions for error propagation.

---

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)