Instance Method


Called or overridden to handle an error that occurs during an attempt to read, save, or revert a document.


- (void)handleError:(NSError *)error userInteractionPermitted:(BOOL)userInteractionPermitted;



An object encapsulating information about an error encountered in an attempt to open, save, or revert a document. The error domain is NSCocoaErrorDomain. The error code is one of the enum constants declared in FoundationErrors.h.


If NO, no attempt is (or should be) made to present a modal view to the user. This value can be NO in cases such as when a save operation fails while the application is being suspended. If this parameter is YES, UIKit or your override may present error information to the user in a modal view and (optionally) allow the user to resolve the error.


Typical UIDocument subclasses do not need to call or override this method. Instead, they can observe the UIDocumentStateChangedNotification notification to be notified of changes in document state. In their notification handler, they can check the value of the documentState property and proceed accordingly. See Conflict Resolution and Error Handling for a discussion of this.

If you are using managed documents (instances of the UIManagedDocument subclass), you must subclass this method and, if desired, the finishedHandlingError:recovered: method. Subclassing allows your app to observe errors in saving or validation. The UIDocumentStateChangedNotification notification does not contain a userInfo dictionary and so does not 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:safelyToURL:forSaveOperation:error:) and that call returns an NSError object by indirection, you should call this method (handleError:userInteractionPermitted:), passing in the error object.

This method is called by the default implementations of openWithCompletionHandler: and saveToURL:forSaveOperation:completionHandler: when UIDocument encounters a reading or writing error, respectively.

If you override this method and do not invoke the superclass implementation (super), you are responsible for the following:

  • Calling finishedHandlingError:recovered: when you are finished handling the error—for example, when the application does not require any additional user feedback about the error.

  • Implementing userInteractionNoLongerPermittedForError: to conclude error handling immediately. If userInteractionPermitted is NO, you should immediately handle the error and call finishedHandlingError:recovered: within the context of the handleError:userInteractionPermitted:

See Also

Resolving Conflicts and Handling Errors

- finishedHandlingError:recovered:

Tells UIKit that you have finished handled the error.

- userInteractionNoLongerPermittedForError:

Sent when it is no longer safe to proceed without immediately handling the error.