Home
Map
NotImplementedExceptionUnderstand the meaning of NotImplementedException and when to use it.
C#
This page was last reviewed on Oct 25, 2021.
NotImplementedException. A C# NotImplementedException has been thrown. An exception's type helps us learn the reason the exception was thrown.
C# type notes. The NotImplementedException indicates in a clear way that the functionality being requested was simply not implemented.
Exception
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.
throw
Detail The method signature returns an integer value. A compile-time error would occur if the method simply had a blank body.
int, uint
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 tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.
This page was last updated on Oct 25, 2021 (edit).
Home
Changes
© 2007-2024 Sam Allen.