C#中是否存在集中式错误处理流程

Pra*_*eep 3 c#

有没有办法集中错误处理或异常处理而不使用try catch方法?

Ali*_*tad 8

使用AppDomainUnhandledException事件:

    static void Main(string[] args)
    {

        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

    }

    static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        // log the exception 
    }
Run Code Online (Sandbox Code Playgroud)

对于ASP.NET使用,您将使用glabal.asax.