answered on 25 Feb 2022, 06:24 AM
| edited on 25 Feb 2022, 06:26 AM
Hi, you can use "ErrorBoundary" since .net 6. Here is an example which catches the errors of all components and then displays an error message. Alternatively you can also send a mail. The benefit of this is, that in case of an error not the whole application stops, but only the affected component.
private ErrorBoundary _errorBoundary;
boolHandleError(Exception ex)
{
var msg = ex.Message;
var trace = ex.StackTrace;
// SEND MAIL TO ADMINreturntrue;
}
This affects all components - if every error in the C# code should be caught globally, I would advise against managing this globally. For this I use try-catch blocks, which optionally log or send a mail in case of an error. With appropriate tests this should happen but rather rarely.