什么"抛出新的NotImplementedException();"做什么呢? [英] What does "throw new NotImplementedException();" do exactly?

查看:145
本文介绍了什么"抛出新的NotImplementedException();"做什么呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一类B继承从类A。在课堂上'一'有一些code,它执行的操作,如果事件不为空。我需要code期间在应用程序中的特定时间火类B。因此,在'B'我订阅了新的处理程序(事件)。

I have a class 'b' that inherits from class 'a'. In class 'a' there is some code that performs an action if an event is not null. I need that code to fire in class 'b' during specific times in the application. So in 'b' I subscribed to a new Handler(event).

如果我离开自动生成的事件'是'类'B'与抛出新的NotImplementedException(); 线,code ++工程/运行的预期。当我删除t指定的异常,应用程序不再正常工作。

If I leave the autogenerated event 'as is' in class 'b' with the throw new NotImplementedException(); line, the code works/runs as expected. As soon as I remove the thow exception, the application no longer works as expected.

那么,什么是抛出新的NotImplementedException 除了抛出异常干什么?

So, what is the throw new NotImplementedException doing besides throwing the exception?

我意识到我可能试图解决我的编码问题,在这一点上走错了路,而且我相信我会找到一个更好的办法来做到这一点(我还在学习),但我的问题仍然存在。为什么该行改变code的结果?

I realize I'm probably trying to solve my coding problem the wrong way at this point, and I am sure I will find a better way to do it (I'm still learning), but my question remains. Why does that line change the outcome of code?

编辑: 我reallize我wan't非常具体的用我的code。不幸的是,由于严格的政策,我不能。我在课堂上'一'的if语句。

I reallize I wan't very specific with my code. Unfortunately, because of strict policies, I can't be. I have in class 'a' an if statement.

if (someEvent != null)

在code作品中,if语句返回true。当工作不正常,它返回假。在课堂上B,唯一的一次应用作品(或if语句返回true),是当我有抛出新的NotImplementedException(); 在班线当我附上了新的情况下,如果自动生成的B的事件方法。

When the code 'works', the if statement is returning true. When it isn't working as expected, it is returning 'false'. In class 'b', the only time the application 'works' (or the if statement returns true), is when I have the throw new NotImplementedException(); line in class 'b's event method that is autogenerated when I attached the new event.

推荐答案

这只是一个例外,至于为什么它意味着你的应用程序作品是完全依赖于code处理任何异常。

It is simply an exception, as for why it means your application "works" is entirely dependent on the code handling any exceptions.

这不是,而不是一个正常的异常特殊例外(不是被从异常和其他人一样派生的其他)。你会用code世代把它看作是一个占位符实现它扔里面的成员。这是一个更容易做到这一点不是让code一代试图了解成员结构,以输出编译code。

It is not a "special" exception as opposed to a normal exception (other than being derived from Exception like the rest). You tend to see it with code generation as a placeholder for implementing the member it is throwing inside. It is a lot easier to do this than have code generation try to understand the member structure in order to output compiling code.

当你说不再按预期工作,我假设它编译。如果从编译随后删除此停止code还是有机会的,你有关于返回值的编译错误。

When you say "no longer works as expected", I am assuming it compiles. If removing this stops the code from compiling then the chances are good you have a compilation error about a return value.

也许,code触发事件预计从处理程序有一定的反应,或者如果没有处理或发生异常则默认响应和进行。你的情况,有一个处理程序,并没有异常,因此需要一个更好的反应?

Perhaps the code that triggers the event expects a certain response from handlers, or if there are no handlers or exceptions occur it defaults the response and carries on. In your case, there is a handler and no exception so it expects a better response?

完整的猜测。

如果有code。在 A ,你需要在 B 使用,请考虑方法,里面的code 保护和任选虚拟如果你需要覆盖的行为。

If there is code in a that you need to use in b, consider making the method that houses the code protected and optionally virtual if you need to override the behaviour.

这篇关于什么"抛出新的NotImplementedException();"做什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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