---
schema_version: "1"
id: fe8f96edd1a98aff733688c699ad47a01f127f4f2a4e011e06b1f77d8a1a550a
title: orElseTry
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dw-runtime-functions-orelsetry.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dw-runtime-functions-orelsetry
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 234d06f8b7830d0c4f41f40c7de016a550bafc32b2e833b5531f8279a16d9948
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# orElseTry

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## orElseTry(TryResult<T>, () -> R): TryResult<T | R>

Function to be use with try in order to chain multiple `try`

_Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>previous</code></p></td><td><p>Previous try result</p></td></tr><tr><td><p><code>orElse</code></p></td><td><p>The next option to try if the previous fails</p></td></tr></tbody></table>

### Example

This example waits shows how to chain different try

#### Source

```DataWeave
%dw 2.0
import * from dw::Runtime
var user = {}
var otherUser = {}
output application/json
---
{
    a: try(() -> user.name!) orElseTry otherUser.name!,
    b: try(() -> user.name!) orElseTry "No User Name"
}
```

#### Output

```JSON
{
  "a": {
    "success": false,
    "error": {
      "kind": "KeyNotFoundException",
      "message": "There is no key named 'name'",
      "location": "\n9|     a: try(() -> user.name!) orElseTry otherUser.name!,\n                                          ^^^^^^^^^^^^^^",
      "stack": [
        "main (org::mule::weave::v2::engine::transform:9:40)"
      ]
    }
  },
  "b": {
    "success": true,
    "result": "No User Name"
  }
}
```
