---
title: "willPresentError(_:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsdocument/willpresenterror(_:)"
---

# willPresentError(_:)

Called when the receiver is about to present an error.

## Declaration

```swift
func willPresentError(_ error: any Error) -> any Error
```

## Parameters

- `error`: The error object that is about to be presented to the user.

## Return Value

Return Value The error that should actually be presented.

## Discussion

Discussion The default implementation of this method merely returns the passed-in error. The returned error may simply be forwarded to the document controller. You can override this method to customize the presentation of errors by examining the passed-in error and, for example, returning more specific information. When you override this method always check the NSError object’s domain and code to discriminate between errors whose presentation you want to customize and those you don’t. For errors you don’t want to customize, call the superclass implementation, passing the original error.

## See Also

### Displaying Errors to the User

- [presentError(_:modalFor:delegate:didPresent:contextInfo:)](appkit/nsdocument/presenterror(_:modalfor:delegate:didpresent:contextinfo:).md)
- [presentError(_:)](appkit/nsdocument/presenterror(_:).md)
- [willNotPresentError(_:)](appkit/nsdocument/willnotpresenterror(_:).md)
