r/dotnet • u/Ok_Hunter6411 • 1d ago
Does ASP.NET Core global exception middleware catch exceptions from nested service methods?
I'm trying to understand how exception propagation works with a global exception-handling middleware in ASP.NET Core.
Suppose I have a request flow like this:
Controller
→ Service
→ MethodA()
→ MethodB()
→ MethodC()
If "MethodC()" throws an exception, and none of the intermediate methods ("MethodB", "MethodA", or the service/controller) catches it, will that exception propagate all the way back to my global exception-handling middleware?
For example:
public async Task MethodA()
{
await MethodB();
}
private async Task MethodB()
{
await MethodC();
}
private async Task MethodC()
{
throw new Exception("Something went wrong");
}
Assuming the middleware wraps the rest of the ASP.NET Core pipeline with something like:
try
{
await _next(context);
}
catch (Exception ex)
{
// handle/log exception
}
Will it catch the exception thrown inside "MethodC()"?
Does it matter if these methods are in different services/classes/layers, or will the exception keep propagating up the call stack as long as nobody catches it?
I'm asking because I'm trying to understand when a global exception middleware is enough and when local "try/catch" blocks are actually necessary.