<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIDocument/handleError(_:userInteractionPermitted:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIDocument(im)handleError:userInteractionPermitted:"
  },
  "title" : "handleError(_:userInteractionPermitted:)"
}
-->

# handleError(_:userInteractionPermitted:)

Handles an error that occurs during an attempt to read, save, or revert a document.

```
func handleError(_ error: any Error, userInteractionPermitted: Bool)
```

## Parameters

`error`

An object encapsulating information about an error encountered in an attempt to open, save, or revert a document. The error domain is <doc://com.apple.documentation/documentation/Foundation/NSCocoaErrorDomain>. The error code is one of the `enum` constants declared in `FoundationErrors.h`.

`userInteractionPermitted`

If <doc://com.apple.documentation/documentation/Swift/false>, no attempt is (or should be) made to present a modal view to the user. This value can be <doc://com.apple.documentation/documentation/Swift/false> in cases such as when a save operation fails while the application is being suspended. If this parameter is <doc://com.apple.documentation/documentation/Swift/true>, UIKit or your override may present error information to the user in a modal view and (optionally) allow the user to resolve the error.

## Discussion

Typical [`UIDocument`](/documentation/UIKit/UIDocument) subclasses don’t need to call or override this method. Instead, they can observe the [`stateChangedNotification`](/documentation/UIKit/UIDocument/stateChangedNotification) notification to be notified of changes in document state. In their notification handler, they can check the value of the [`documentState`](/documentation/UIKit/UIDocument/documentState) property and proceed accordingly. See [`Resolve conflicts and handle errors`](/documentation/UIKit/UIDocument#Resolve-conflicts-and-handle-errors) for a discussion of this.

If you’re using managed documents (instances of the [`UIManagedDocument`](/documentation/UIKit/UIManagedDocument) subclass), you must subclass this method and, if desired, the [`finishedHandlingError(_:recovered:)`](/documentation/UIKit/UIDocument/finishedHandlingError(_:recovered:)) method. Subclassing allows your app to observe errors in saving or validation. The [`stateChangedNotification`](/documentation/UIKit/UIDocument/stateChangedNotification) notification doesn’t contain a `userInfo` dictionary and so doesn’t convey specific error information.

If you directly call any of the advanced reading and writing methods that have an error-object parameter (for example, [`writeContents(_:andAttributes:safelyTo:for:)`](/documentation/UIKit/UIDocument/writeContents(_:andAttributes:safelyTo:for:))) and that call returns an <doc://com.apple.documentation/documentation/Foundation/NSError> object by indirection, you should call this method ([`handleError(_:userInteractionPermitted:)`](/documentation/UIKit/UIDocument/handleError(_:userInteractionPermitted:))), passing in the error object.

This method is called by the default implementations of [`open(completionHandler:)`](/documentation/UIKit/UIDocument/open(completionHandler:)) and [`save(to:for:completionHandler:)`](/documentation/UIKit/UIDocument/save(to:for:completionHandler:)) when [`UIDocument`](/documentation/UIKit/UIDocument) encounters a reading or writing error, respectively.

If you override this method and don’t invoke the superclass implementation (`super`), you’re responsible for the following:

- Calling [`finishedHandlingError(_:recovered:)`](/documentation/UIKit/UIDocument/finishedHandlingError(_:recovered:)) when you’re finished handling the error — for example, when the application doesn’t require any additional user feedback about the error.
- Implementing [`userInteractionNoLongerPermitted(forError:)`](/documentation/UIKit/UIDocument/userInteractionNoLongerPermitted(forError:)) to conclude error handling immediately. If `userInteractionPermitted` is <doc://com.apple.documentation/documentation/Swift/false>, you should immediately handle the error and call [`finishedHandlingError(_:recovered:)`](/documentation/UIKit/UIDocument/finishedHandlingError(_:recovered:)) within the context of the [`handleError(_:userInteractionPermitted:)`](/documentation/UIKit/UIDocument/handleError(_:userInteractionPermitted:)).

---

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)