Handling exceptions globally without try-catch

Cenk 1,041 Reputation points
2022-10-03T10:01:06.707+00:00

Hello,

I am working on the Blazor Server application, using NLog to log exceptions into a database table. I wonder if there is a way to catch all exceptions without using try-catch and the connection between the client and server isn't broken when an error occurs and the circuit remains alive.

Thanks in advance.

Developer technologies | .NET | Blazor
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sreeju Nair 12,756 Reputation points
    2022-10-03T10:16:41.773+00:00

    When you dont use try - catch and your code throws an exception, this is considered as unhandled exceptions. Refer the following URL to understand how Blazor handles unhandled exceptions.

    https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/handle-errors?view=aspnetcore-6.0#blazor-server-unhandled-exceptions

    To log the unhandled error, you can pass a custom error component as a cascading value to the child components. Refer the following to understand how you can do the same.

    https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/handle-errors?view=aspnetcore-6.0#alternative-global-exception-handling

    Hope this helps

    1 person found this answer helpful.

  2. Cenk 1,041 Reputation points
    2022-10-09T14:51:06.153+00:00

    Sorry but I don't understand how to use.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.