---
title: "withContinuation(of:throwing:_:)"
framework: Swift
role: symbol
role_heading: Function
platforms: [iOS 27.0+, iPadOS 27.0+, Mac Catalyst 27.0+, macOS 27.0+, tvOS 27.0+, visionOS 27.0+, watchOS 27.0+]
path: "swift/withcontinuation(of:throwing:_:)"
---

# withContinuation(of:throwing:_:)

Invokes the passed in closure with a non-copyable continuation for the current task.

## Declaration

```swift
nonisolated(nonsending) func withContinuation<Success, Failure>(of: Success.Type = Success.self, throwing: Failure.Type, _ body: (consuming Continuation<Success, Failure>) -> Void) async throws(Failure) -> sending Success where Failure : Error, Success : ~Copyable
```

## Parameters

- `of`: The Success type returned by the continuation
- `throwing`: The Failure type that may be thrown
- `body`: A closure that takes a Continuation parameter

## Return Value

Return Value The value the continuation is resumed with

## Discussion

Discussion The body of the closure executes synchronously on the calling task, and once it returns the calling task is suspended. It is possible to immediately resume the task, or escape the continuation in order to complete it afterwards, which will then resume the suspended task. You must invoke the continuation’s resume method exactly once. The continuation is a noncopyable type, and therefore multiple resume calls are prevented at compile time (as resuming the continuation consumes it). However, if the continuation is dropped without being resumed, the program traps.

## See Also

### Continuations

- [Continuation](swift/continuation.md)
- [withContinuation(of:_:)](swift/withcontinuation(of:_:).md)
- [CheckedContinuation](swift/checkedcontinuation.md)
- [withCheckedContinuation(function:_:)](swift/withcheckedcontinuation(function:_:).md)
- [withCheckedThrowingContinuation(function:_:)](swift/withcheckedthrowingcontinuation(function:_:)-13yf6.md)
- [withCheckedThrowingContinuation(function:_:)](swift/withcheckedthrowingcontinuation(function:_:)-2k46m.md)
- [UnsafeContinuation](swift/unsafecontinuation.md)
- [withUnsafeContinuation(_:)](swift/withunsafecontinuation(_:).md)
