As of now, Logic Apps doesn’t offer a way to throw exceptions. This idea was added to the Logic Apps feedback forum, but the product team never took it forward. That said, in workflows, we often have scenarios where we want to throw an application exception and log that exception.
Some people had suggested to imitate this by purposefully adding a failure action like this
This could work. You could then add a failure scope to capture all the error. However, with this, we are not able to pass the failure exception.
I created a simple azure function, which will always throw an error to the calling Logic App. You can also pass the error details to the function and it will return back the details for you.
Let’s look at a scenario :-
- Logic App calls a long running durable orchestrator for transforming a message (This transformation has c# extension methods).
- The long running durable function returns the response to the callback url.
- If the process fails in the transformation, the function adds a Status header with the value “Failure” and sends the response back to the Logic App.
- Now, in this scenario, if the Status is “Failure”, I need to throw an exception.
I then invoke a condition and check the header field “Status”. If the Status is failure, then I execute the Throw Exception function
In the exception block, we could then use outputs(‘Throw_Exception’)[‘body’]?[‘detail’] to get the error details.
Although this is not an efficient way, this could be used until the product team rolls out an out of the box action for throwing exceptions.