I have a scenario, where I create Tasks as a part of a Webapi call. When an exception happens in a task it does not get caught and I can't figure out how to implement a global exception handler for this.
In particular:
- This question and the solution for Web API Global Error Handling does not work for Tasks. I'm guessing because these are executed on threads webapi has no awareness of.
- Subscribing to AppDomain.UnhandledException Event does not work either. Possibly because web host catches all the unhandled exceptions and is not letting them bubble up.
If you believe that any of the above should work let me know, and I'll come up with a small reproducible example of what I'm observing. Otherwise, what is the right way of doing this, that would work?
[HttpGet]
public IQueryable<Thingies> Thingies()
{
Task.Run(() => { throw new ApplicationException("How do I catch all of these globally?"); });
return _db.Thingies;
}
I also should note that the application does not have dependencies on System.Web
and I would not like to introduce them.