C# NotImplementedException

Warning

In the C# language, an exception's type helps you learn the reason the exception was thrown. The NotImplementedException, then, indicates in a clear way that the functionality being requested was simply not implemented.

This C# exception article demonstrates NotImplementedException.

Example

To start, the NotImplementedException is not a debugging construct, but it 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. This can help you as you compile a complex system as it is developed. This example demonstrates the NotImplementedException used in an unimplemented method.

Program that uses NotImplementedException [C#]

using System;

class Program
{
    static void Main()
    {
	Method();
    }

    static int Method()
    {
	// Leave this as a stub for now.
	throw new NotImplementedException();
    }
}

Result
    Exception message is printed to screen.

Keep it compiling. In the example, please notice how the method returns an integer value. A compile-time error would occur if the method simply had a blank body; the NotImplementedException prevents this from happening and so keeps the program compilable.

Programming tip

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 featured quite prominently. Therefore, when the NotImplementedException occurs, you will realize that the problem is unfinished code and not any other sort of design error.

Summary

Visual Studio logo (Copyright Microsoft)

Through specific exception types, you can accurately describe the problems that occur in your program. As a descriptive exception type, the NotImplementedException is useful as a way to compile an unfinished program. Finally, Visual Studio inserts the NotImplementedException in method stubs such as in Windows Forms programs, making it a known standard.

Exception Handling
.NET