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

# 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"
  }
}
```
