Closed slogan3685 closed 1 month ago
Looks similar to #912
The current design is to throw an aggregate exception which contains the other exception which was thrown. We plan on changing the behavior in the next major version change, so that it will throw the actual exception instead of an aggregate exception.
My current workaround for now:
static Exception GetSpecificException(AggregateException exception) =>
exception.Flatten().InnerExceptions.FirstOrDefault()?.InnerException ?? exception;
With Microsoft.Azure.Functions.Worker
1.21.0, I am seeing user code exception thrown in a trigger caught in the middleware, as expected, and no longer need the workaround.
(HTTP, both, Built-in HTTP model and ASP.NET Core integration)
I've used HTTP and ASB triggers to validate this. cc @kshyju
This is no longer relevant as it has been addressed in recent versions of the SDK (1.16+)
Based on the sample project I have the following middleware...
...function, and...
...startup code
When I run this, the middleware catches an AggregateException containing the ApplicationException that I threw. Is this the expected behaviour, meaning I need to inspect the exception(s) within and decide how to handle them? Fwiw, if the function is not async then it works as I expected - the middleware catches the ApplicationException directly.