为什么UnhandledExceptionEventArgs.ExceptionObject是一个对象而不是异常? [英] Why is UnhandledExceptionEventArgs.ExceptionObject an object and not an Exception?

查看:111
本文介绍了为什么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

这篇关于为什么UnhandledExceptionEventArgs.ExceptionObject是一个对象而不是异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆