Reputation: 1214
Is it possible to throw an exception in a Logic App?
Specifically, I'm trying to throw an exception inside of a scope. Then in the run after of the scope I'd check if it failed and inspect it for errors. I tried using a terminate inside of a scope, but that terminates the entire logic app run.
Upvotes: 8
Views: 10118
Reputation: 32390
int('__ERROR__')
int('__ERROR__') ## this will cause the enclosing scope to fail ## the string __ERROR__ cannot be cast to integer
Upvotes: 6
Reputation: 1380
As an updated solution we can use Terminate control, Terminate control has 3 status: Failed, Canceled, and Succeeded.
Upvotes: 10
Reputation: 21
It seems like there still is no option for this inside Logic App or its little brother Power Automate / Microsoft Flow.
The way I have come up with and have used in some flows, is I simply add an action for something I know for a fact will fail.
The simplest (and probably the cheapest as the built-in actions cost less in Logic Apps, even if we are talking fractions of a dollar here either way) is probably to initialize a variable, e.g. called ThrowException with type of integer. Then a "Set variable" action is added wherever I want my flow to fail, where I set the value (remember it is of type integer) to any string expression. I simply use the expression string('Exception').
Since the value is set via an expression this is still a valid template, but will fail upon runtime when the value is actually being set. After this, simply use parallel branches, with appropriate Run After settings, as usual.
Upvotes: 2
Reputation: 11040
No, there is no Action or Connector directly analogous to something like a throw
in C#.
The closest you can get right now would be to do something like use another LogicApp instead of a scope from which you can return a specific status code.
Upvotes: 4