---
title: checkCancellation()
framework: swift
role: symbol
role_heading: Type Method
path: swift/task/checkcancellation()
---

# checkCancellation()

Throws an error if the task was canceled.

## Declaration

```swift
static func checkCancellation() throws
```

## Discussion

Discussion The error is always an instance of CancellationError. note: isCancelled()

## See Also

### Canceling Tasks

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