Why do AppDomain exceptions invariably terminate the application?

前端 未结 3 900
-上瘾入骨i
-上瘾入骨i 2021-02-06 08:21

This is related to a previous question.

What I\'m trying to understand now is how come UI thread exceptions can be prevented from terminating the application while non-U

3条回答
  •  一向
    一向 (楼主)
    2021-02-06 08:44

    Does this help at all?

    Improved Unhandled Exception behavior in .NET 2.0

    Also, this code seems to "die quietly". Are you looking for something else?

    using System;
    
    namespace UnhandledException
    {
        class Program
        {
            static void Main(string[] args)
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomainUnhandledException;
    
                throw new NotImplementedException();
            }
    
            static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
            {
                Exception exception = (Exception)e.ExceptionObject;
                System.Console.WriteLine("exception=[" + exception.ToString() + "]");
    
                Environment.Exit(-1);
            }   
        }
    }
    

提交回复
热议问题