Example. The NotImplementedException should not be thrown in completed programs. When adding a method, you may want the method to exist but you may not be able to implement it yet.
And This can help with a complex system as it is developed. This example uses NotImplementedException in an unimplemented method.
Result The NotImplementedException prevents this from happening and so keeps the program compiling.
using System;
class Program
{
static void Main()
{
Method();
}
static int Method()
{
// Leave this as a stub.
throw new NotImplementedException();
}
}Unhandled exception. System.NotImplementedException: The method or operation is not implemented.
at Program.Method() in /home/sam/programs/consoletemp/Program.cs:line 13
at Program.Main() in /home/sam/programs/consoletemp/Program.cs:line 7
Aborted (core dumped)
Self-documenting type. When using exceptions, you want to describe the problem as much as possible through the type itself. In error messages, the type of the exception is prominently featured.
Detail When the NotImplementedException occurs, you will realize that the problem is unfinished code—not another error.
Summary. As a descriptive exception type, the NotImplementedException is useful as a way to compile an unfinished program. Visual Studio inserts it in method stubs.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Oct 25, 2021 (edit).