Skip to content

IExceptionHandler not being called when using UseDeveloperExceptionPage() #52622

@jamezamm

Description

@jamezamm

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Program.cs:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddExceptionHandler<GlobalExceptionHandler>();

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<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
    {
        ...

        return false;
    }
}

As stated within the documentation , 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

Metadata

Metadata

Assignees

Labels

DocsThis issue tracks updating documentationarea-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-diagnosticsDiagnostic middleware and pages (except EF diagnostics)

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions