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

# orElseTry

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

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

Function to use with `try` to chain multiple `try` requests.

_Introduced in DataWeave version 2.2.0._

### 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>Result from a previous call to <code>try</code>.</p></td></tr><tr><td><p><code>orElseTry</code></p></td><td><p>Argument to try if the <code>previous</code> argument 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"
  }
}
```
