Message when net core exception occurs

Asked

Viewed 31 times

-1

I have 1 to 1 relationship between company and user

but when the user has already registered 1 company and try to register another I want to show a message other than

inserir a descrição da imagem aqui

how can I do?

  • Hello Thais, do not post pictures of your problem, give preference to put in question, formatted, the point of code where the problem occurs.

  • Instead of letting the error happen, it might be a good thing to validate if the user no longer has a registered company.

1 answer

0

You have two chances to catch these mistakes (both can be used at the same time):

Try/Catch

try
{
    // Code
}
catch (Exception ex)
{
   // Handle ex
}

Or you use the native middleware for handling exceptions of the . NET Core, which can be configured using the method UseExceptionHandler. The Boilerplate of this code is already generated when we create a project so you can take a look at this code and adapt to your needs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.