dotnet / dotnet/aspnetcore

IExceptionHandler not being called when using UseDeveloperExceptionPage()

Open
#52,622 9 comments 4 reactions 0 assignees View on GitHub
area-middleware Docs feature-diagnostics
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Program.cs:

```
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddExceptionHandler();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
else
{
app.UseDeveloperExceptionPage();
}

...

app.Run();
```

GlobalExceptionHandler.cs:

```
public class GlobalExceptionHandler : IExceptionHandler
{
public async ValueTask TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
{
...

return false;
}
}
```

As stated within the [documentation ](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling?view=aspnetcore-8.0), registered exception handlers are triggered when using either **UseExceptionHandler()** or **UseDeveloperExceptionPage()**.

When in production (**UseExceptionHander()**) the GlobalExceptionHandler is triggered successfully, while in development (**UseDeveloperExceptionPage()**) the GlobalExceptionHandler is **NOT** triggered.

### .NET Version

8

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.