Easy guide on use of Try() in DataWeave
Introduction
Easy guide on use of Try() in DataWeave
Introduction
try<T>(delegate: () -> T): TryResult<T>
Evaluates the delegate function and returns an object with success: true and result if the delegate function succeeds, or an object with success: false and error if the delegate function throws an exception.
This function is present under Runtime Module
Based on the output of the try function, you can add conditional logic to execute when the result is success: true or success: false.
OrElseTry() and orElse()
- OrElseTry() is used with try() to chain multiple try requests. When try() method fails, then orElseTry() will run
- OrElse() will return the result of the orElse() argument if the result from a previous call of try() or orElseTry() fails
Example
This example calls the try function using the user function as argument. The function user will check weather the passed argument is empty and calls fail if the passed argument is empty.

Argument of orElseTry() will return the result when the try function fails

Argument of orElse() will return the result when the try function fails and orElseTry() will throw error

Exception
- Try() method will throw error of type UserException with success: false

- OrElseTry() will throw KeyNotFoundException with success:false

Hope you enjoyed this blog post. If you have any questions or an idea about how to improve the article feel free to contact me.
LinkedIn Profile: https://www.linkedin.com/in/vaishali-malviya-774b06134/
Stay in touch!
메타데이터
- post_id
- 565f9ff65482
- slug
- easy-guide-on-use-of-try-in-dataweave-565f9ff65482
- url
- https://medium.com/@vaishali.malviya/easy-guide-on-use-of-try-in-dataweave-565f9ff65482
- canonical_url
- https://medium.com/@vaishali.malviya/easy-guide-on-use-of-try-in-dataweave-565f9ff65482
- author_url
- https://medium.com/@vaishali.malviya
- status
- ok
- fetched_at
- 2026-07-25 12:44:45