---
title: "withCancellationHandler(handler:operation:)"
framework: swift
role: symbol
role_heading: Type Method
path: "swift/task/withcancellationhandler(handler:operation:)"
---

# withCancellationHandler(handler:operation:)

## Declaration

```swift
static func withCancellationHandler<T>(handler: @Sendable () -> Void, operation: () async throws -> T) async rethrows -> T
```

## See Also

### Deprecated

- [Task.Group](swift/task/group.md)
- [Task.Handle](swift/task/handle.md)
- [Task.Priority](swift/task/priority.md)
- [CancellationError()](swift/task/cancellationerror().md)
- [getResult()](swift/task/getresult().md)
- [get()](swift/task/get()-4i2gt.md)
- [get()](swift/task/get()-4ohks.md)
- [sleep(_:)](swift/task/sleep(_:).md)
- [suspend()](swift/task/suspend().md)
- [runDetached(priority:operation:)](swift/task/rundetached(priority:operation:)-88zf5.md)
- [runDetached(priority:operation:)](swift/task/rundetached(priority:operation:)-8s8lh.md)
- [withGroup(resultType:returning:body:)](swift/task/withgroup(resulttype:returning:body:).md)
