Skip to content

IExceptionHandler not being called when using UseDeveloperExceptionPage() #52622

Open

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions