Home c# for what is needed new notimplementedexception ()

for what is needed new notimplementedexception ()




I can not understand to the end, for which the designs of the type Throw new notimplementedexception () are used, and what THROW , for example, in TRY-CATCH Differs from Throw New .

Answer 1, Authority 100%

In .NET there are several “systemic” exceptions that exist to report the reason for the absence of the method, but which do not need to catch:

  • notimplementedexception – the method is not implemented, but will be implemented in the future . Variation on the comment topic TODO, which leads to a drop in execution.

  • NotSupportedException – the method is not implemented and will never be implemented . It is used if the base class or the implemented interface has a wide API, and the purposes do not intend to implement all methods (for example, because some possibility is not supported).

By default, when implementing the IDE interface, generates methods with Throw New NotimplemenException () , assuming that you are implementing them. If you are not going to do this (for example, your collection relates ilist & lt; & gt; , but does not support recording), then you should replace this code on Throw New Not SupportedException ("Foo IS not Supported Due To to ... ") with a message about the cause of lack of implementation (for example, in the case of a collection only for reading a message can be” a read-only collection cannot be changed. “).

If you want to check the code in operation, and Throw New Nie interferes you, then you can replace the code on the plug, for example, Return NULL; // TODO IMPLEMENT FOOL () METHOD .

Answer 2, Authority 72%

I can not understand to the end for what the designs of the view type new notimplemenidedexception ()

Quite often you need to switch to a completely different piece of code, and some


safely forgotten and force first to exhibit, and only then remember that the code was not really completed. In other words, it is good able to get on the unfinished component.

than Throw for example in try-catch different from Throw New

Throw can only be used in Catch block, Throw New – almost any location code.

Throw throws original exception. This design is useful when you need to make any action when processing an exception, for example, to log out, and then we break further:

Catch (MyeException E)
  Logger.log (E);

Throw New throws New instance exceptions. Often this design is used to wrap a low-level exception (for example, sqlexception ) in a more own high-level exception (for example, UserNotFoundException ). Important moment: information about the original exclusion is lost! When debugging, it is mostly interested in strokes, so it is important to always include the original exception as InNerException :

  Throw New UserNotFoundException ("CANNOT FIND User", E);

Answer 3, Authority 33%

Throw Offer without expression can only be used in Catch block. In this case, it will redirect the current exception further beyond the limits of this Catch block.

Consider an example.

  // ...
  // Dah - I will choose an exception
  // Since I still do not know what to do in this part of the program
  Throw New NotimplementeDextException ();
Catch (NotimpleMenteDextException)
  Console.WriteLine ("Just ignore this exception to better times");
Catch (Exception)
// Alas, this is not my exception. I will bring it
  // let others understand him

Answer 4, Authority 28%

NotimpleMenteDextException is used when creating “plugs” methods. When the method is described, but does not contain implementations as such. More details you can read on MSDN .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions