Versão
Idioma

Blazor UI: Error Handling

Blazor, by default, shows a yellow line at the bottom of the page if any unhandled exception occurs. However, this is not useful in a real application.

ABP provides an automatic error handling system for the Blazor UI.

  • Handles all unhandled exceptions and shows nice and useful messages to the user.
  • It distinguishes different kind of exceptions. Hides internal/technical error details from the user (shows a generic error message in these cases).
  • It is well integrated to the server side exception handling system.

Basic Usage

There are different type of Exception classes handled differently by the ABP Framework.

UserFriendlyException

UserFriendlyException is a special type of exception. You can directly show a error message dialog to the user by throwing such an exception.

Example

@page "/"
@using Volo.Abp

<Button Clicked="TestException">Throw test exception</Button>

@code
{
    private void TestException()
    {
        throw new UserFriendlyException("A user friendly error message!");
    }
}

ABP automatically handle the exception and show an error message to the user:

blazor-user-friendly-exception

You can derive from UserFriendlyException or directly implement IUserFriendlyException interface to create your own Exception class if you need.

You can use the localization system to show localized error messages.

BusinessException and Other Exception Types

See the exception handling document to understand different kind of Exception class and interfaces and other capabilities of the Exception Handling system.

Generic Errors

If the thrown Exception is not a special type, it is considered as generic error and a generic error message is shown to the user:

blazor-generic-exception-message

All error details (including stack trace) are still written in the browser's console.

Server Side Errors

Errors (like Validation, Authorization and User Friendly Errors) sent by the server are processed as you expect and properly shown to the user. So, error handling system works end to end without need to manually handle exceptions or manually transfer server-to-client error messages.

See Also

Esta página foi útil?
Por favor, faça uma seleção.
Obrigado pelo seu valioso feedback!

Observe que, embora não possamos responder aos comentários, nossa equipe usará seus comentários para melhorar a experiência.

Neste documento
Mastering ABP Framework Book
Dominando a estrutura ABP

Este livro o ajudará a obter uma compreensão completa da estrutura e das técnicas modernas de desenvolvimento de aplicativos da web.