The Wayback Machine - https://web.archive.org/web/20210527072036/https://github.com/dotnet/aspnetcore/issues/33065
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow exception propagation during view render #33065

Open
gyankov opened this issue May 27, 2021 · 0 comments
Open

Allow exception propagation during view render #33065

gyankov opened this issue May 27, 2021 · 0 comments

Comments

@gyankov
Copy link

@gyankov gyankov commented May 27, 2021

Currently the view.RenderAsync method is executed within a try block. Thus, if an exception is thrown during rendering, no error message is displayed which makes it hard to track.

Is your feature request related to a problem? Please describe.

In a custom html helper which internally uses HtmlHelper.Editor, if the editor view is misconfigured and throws an exception, instead of showing a meaningful exception message, the html helper simply has no output which is confusing and a nightmare to track down.

Describe the solution you'd like

try
{
    viewContext.Writer = writer;

    DiagnosticListener.BeforeView(view, viewContext);

    await view.RenderAsync(viewContext);

    DiagnosticListener.AfterView(view, viewContext);
}
catch
{
    if (viewContext.PropagateExceptions)
    {
         throw;
    }
}
finally
{
    viewContext.Writer = oldWriter;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant