What does “throw new NotImplementedException();” do exactly?

前端 未结 5 601
Happy的楠姐
Happy的楠姐 2021-01-23 06:01

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\'

5条回答
  •  没有蜡笔的小新
    2021-01-23 06:19

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

    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.

    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.

    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?

    Complete guesswork.

    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.

提交回复
热议问题