Contact Us 1-800-596-4880

orElse

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

Returns the result of the orElse if the previous try result failed if not returns the result of the previous

Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.

Parameters

Name Description

previous

Previous try result

orElse

The next option to try if the previous fails

Example

This example demonstrates how to specify the next expression to evaluate after a call to try fails.

Source

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

Output

{
  "a": "No User Name",
  "b": "DW"
}