---
title: "download(_:didFailWithError:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsurldownloaddelegate/download(_:didfailwitherror:)"
---

# download(_:didFailWithError:)

Sent if the download fails or if an I/O error occurs when the file is written to disk.

## Declaration

```swift
optional func download(_ download: NSURLDownload, didFailWithError error: any Error)
```

## Parameters

- `download`: The URL download object sending the message.
- `error`: The error that caused the failure of the download.

## Discussion

Discussion Any partially downloaded file will be deleted. Special Considerations Once the delegate receives this message, it will receive no further messages for download.

## See Also

### Download Completion

- [downloadDidFinish(_:)](foundation/nsurldownloaddelegate/downloaddidfinish(_:).md)
