Why is UnhandledExceptionEventArgs.ExceptionObject an object and not an Exception?

后端 未结 2 2053
时光取名叫无心
时光取名叫无心 2020-12-04 17:33

Why is UnhandledExceptionEventArgs.ExceptionObject an object and not an Exception?

I am attaching to AppDomain.UnhandledException

2条回答
  •  眼角桃花
    2020-12-04 18:03

    This cannot be typed to Exception because it's possible to throw objects in .Net that do not derive from System.Exception. This is not possible in C# or VB.Net but it is possible in other CLR based languages. Hence the API must support this possibility and uses the type object.

    So while it shouldn't ever be null, it may not in fact be a System.Exception.

    See CLI spec section 10.5 (specifically CLS rule 40) for more details

提交回复
热议问题