Sunday, July 30, 2006

The NotImplementedException

The NotImplementedException is a very simple, but useful class. It's intent is to indicate, obviously, that a method is not implemented yet. This is very simple to search for while editing code and also something you can't miss at runtime.

Okay, let's give it a try. Open up any C# project, move inside any method, and type a call to a method that you are sure does not exist. For example:

TestNotImplementedException();

Select the above text, right click and choose "Generate Method Stub". If you were surprised as I was that instead of generating:

throw new NotImplementedException();

Visual Studio generated:

throw new Exception("The method or operation is not implemented.");

Read Anson Horton's blog post that describes why the decision was made, and how by editing a snippet file you can change the default behavior.


0 Comments:

Post a Comment

<< Home