Intercept all unprocessed Exception at the .NET program.

xiaoxiao2021-03-06  51

The .NET program is always divided into two situations, obviously, WebForm (ASP.NET) and WinForm

Basically, you can configure a special "ErrorPage" in Web.config, like this:

Such all errors are positioned to Error.aspx, which is much better than a 5xx error directly to the user.

There is also a way to be more standard, that is, using System.Web.httpApplication.Estem.Eb.httpApplication.Error events, you can bind any legally signed functions to do anything, such as error logs.

Windows form is basically the same, there are system.windows.forms.Application.threadException events, this record exception can make your Windows program won't die (at least you will send you error report to MS, actually Serious mistakes still cannot be recovered), there is a chance to give the user a prompt before "dead", then continue to run.

This is much better than the Try / Catch statement outside Application.Run, because although it can also capture exceptions, the program is still forced to end.

Here is an example of CodeProject.

转载请注明原文地址:https://www.9cbs.com/read-83302.html

New Post(0)