为什么UnhandledExceptionEventArgs.ExceptionObject的对象,而不是一个例外?而不是、对象、UnhandledExceptionEventArgs、Excepti

由网友(花开淡墨)分享简介:为什么 UnhandledExceptionEventArgs.ExceptionObject 的对象,而不是一个异常?我连接到 AppDomain.UnhandledException 。我想投 UnhandledExceptionEventArgs.ExceptionObject 到 Exeption 和inter...

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

我连接到 AppDomain.UnhandledException

我想投 UnhandledExceptionEventArgs.ExceptionObject Exeption 和interogate它。

和考虑到这一点将它永远是空?

的MSDN文档不exatly有用的。

  

获取未处理的异常对象。

解决方案

这不能被输入到异常,因为它可能扔在.NET对象不从System.Exception派生。这是不可能的C#或VB.Net但也可以在其他的CLR基于语言。因此,API必须支持这种可能性,并使用类型的对象。

所以,尽管它不应该永远是零,它可能不是实际上是一个System.Exception的。

年底了,沙雕网友们拿出了他们的年度珍藏

请参阅CLI规范第10.5(特别是CLS规则40)了解详情。

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

I am attaching to AppDomain.UnhandledException.

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

And with this in mind will it ever be null?

The MSDN documentation is not exatly useful.

Gets the unhandled exception object.

解决方案

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

阅读全文

相关推荐

最新文章