为什么UnhandledExceptionEventArgs.ExceptionObject是一个对象而不是异常?

为什么UnhandledExceptionEventArgs.ExceptionObject是一个对象而不是异常?

问题描述:

为什么 UnhandledExceptionEventArgs.ExceptionObject 一个对象而不是异常

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

我附加到 AppDomain.UnhandledException

我想投递 UnhandledExceptionEventArgs.ExceptionObject Exeption 并与其进行interogate。

I would like to cast UnhandledExceptionEventArgs.ExceptionObject to an Exeption and interogate it.

这个想法会不会是null?

And with this in mind will it ever be null?

MSDN文档不是非常有用的。


获取未处理的异常对象。 / p>

Gets the unhandled exception object.


这不能键入到Exception,因为可以在.Net中抛出不派生自System.Exception。这在C#或VB.Net中是不可能的,但是在其他基于CLR的语言中是可能的。因此,API必须支持这种可能性并使用类型对象。

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.

所以虽然它不应该为空,但实际上可能不是System.Exception。

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

有关更多详细信息,请参阅CLI规范第10.5节(特别是CLS规则40)

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