---
title: "init(upstream:handler:)"
framework: combine
role: symbol
role_heading: Initializer
path: "combine/publishers/trycatch/init(upstream:handler:)"
---

# init(upstream:handler:)

Creates a publisher that handles errors from an upstream publisher by replacing the failed publisher with another publisher or by throwing an error.

## Declaration

```swift
init(upstream: Upstream, handler: @escaping (Upstream.Failure) throws -> NewPublisher)
```

## Parameters

- `upstream`: The publisher from which this publisher receives its elements.
- `handler`: A closure that accepts the upstream failure as input and either returns a publisher to replace the upstream publisher. If this closure throws an error, the publisher terminates with the thrown error.
