Action.Try

Updated on

Action.Try is a Power Query M function that creates an action that executes a specified action, and catches and returns any errors that occur during its execution.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Action.Try( action as any ) as any

Description

Creates an action that executes action, catches any errors that occur while executing the action, and returns a record containing a HasError field and either a Value or Error field depending on whether the action executed successfully.

Examples

Creates an action that will try the execution of a second action that throws an error. The result of the Try action is the error record:

[HasError = true, Error = [Reason = "Expression.Error", Message = "Error!", Detail = ]

Action.Try( Action.Sequence( {() => Action.Return( error "Error!" )} ) )

Creates an action that will try the execution of a second action that returns a result. The result of the Try action is a success record:

[HasError = false, Value = "Success!"]

Action.Try( Action.Sequence( {() => Action.Return( "Success!" )} ) )

Other functions related to Action.Try are:

Contribute » | Contributors: Rick de Groot