%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"
}
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 try result |
|
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.



