How can catched exception be null (not NullReferenceException)?

放肆的年华 提交于 2019-12-05 08:34:38

How are you determining that e is in fact null? I've tried a few samples and read through the CLI spec on exceptions and it does not seem to allow for a exception value being null. Additionally if it was null, it would not have a type and hence wouldn't be able to meet the filter criteria for being of type exception.

Are you using the debugger to verify this value? If so, try switching it to an inline assert.

Are you positive you were off the Exception e line?

try
{
    //Some Code here
}
catch (Exception e)
{
    int i = 0; // breakpoint here
}

I only ask this because I have never, ever seen this kind of behaviour and I know that if you breakpoint Exception e, e seems to be null. On the next line it becomes not null.

It is possible that the exception being thrown is not CLS Compliant, which really shouldn't be catchable by a Try/Catch with a filter.

You should only be able to catch a CLS Compliant with a try {} catch {} with no exception "argument"

I have got the same situation, too. It happened to be a bug of Eclipse debugger. Eclipse restart is enough - runtime exception becomes normal, not null.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!