---
title: CancellationError
framework: swift
role: symbol
role_heading: Structure
path: swift/cancellationerror
---

# CancellationError

An error that indicates a task was canceled.

## Declaration

```swift
struct CancellationError
```

## Overview

Overview This error is also thrown automatically by Task.checkCancellation(), if the current task has been canceled.

## Topics

### Initializers

- [init()](swift/cancellationerror/init().md)

## Relationships

### Conforms To

- [Error](swift/error.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Canceling Tasks

- [cancel()](swift/task/cancel().md)
- [isCancelled](swift/task/iscancelled-swift.property.md)
- [isCancelled](swift/task/iscancelled-swift.type.property.md)
- [checkCancellation()](swift/task/checkcancellation().md)
- [withTaskCancellationHandler(handler:operation:)](swift/withtaskcancellationhandler(handler:operation:).md)
- [withTaskCancellationHandler(operation:onCancel:isolation:)](swift/withtaskcancellationhandler(operation:oncancel:isolation:).md)
