Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 95379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:38:56+00:00 2026-05-10T23:38:56+00:00

This really, really urks me, so I hope that someone can give me a

  • 0

This really, really urks me, so I hope that someone can give me a reasonable justification for why things are as they are.

NotImplementedException. You are pulling my leg, right?

No, I’m not going to take the cheap stab at this by saying, ‘hang on, the method is implemented – it throws a NotImplementedException.’ Yes, that’s right, you have to implement the method to throw a NotImplementedException (unlike a pure virtual function call in C++ – now that makes sense!). While that’s pretty damn funny, there is a more serious problem in my mind.

I just wonder, in the presence of the NotImplementedException, how can anyone do anything with .Net? Are you expected to wrap every abstract method call with a try catch block to guard against methods that might not be implemented? If you catch such an exception, what the heck are you supposed to do with it??

I see no way to test if a method is actually implemented without calling it. Since calling it may have side effects, I can’t do all my checks up-front and then run my algorithm. I have to run my algorithm, catch NotImplementedExceptions and the some how roll back my application to some sane state.

It’s crazy. Mad. Insane. So the question is: Why does the NotImplementedException exist?

As a preemptive strike, I do not want anyone to respond with, ‘because designers need to put this in the auto-generated code.’ This is horrid. I would rather the auto-generated code not compile until you supply an implementation. For example, the auto generated implementation could be ‘throw NotImplementedException;’ where the NotImplementedException is not defined!

Has anyone ever caught and handled a NotImplementedException? Have you ever left a NotImplementedException in your code? If so, did this represent a time bomb (ie, you accidentally left it there), or a design flaw (the method should not be implemented and will never be called)?

I’m very suspicious of the NotSupportedException also… Not supported? What the? If it’s not supported, why is it part of your interface? Can anyone at Microsoft spell improper inheritance? But I might start another question for that if I don’t get too abuse for this one.

Additional info:

This is an interesting read on the subject.

There seems to be a strong agreement with Brad Abrams that ‘NotImplementedException is for functionality that is just not yet implemented, but really should (and will be). Something like what you might start with when you are building a class, get all the methods there throwing NotImplementedException, then flush them out with real code…’

Comments from Jared Parsons are very weak and should probably be ignored: NotImplementedException: Throw this exception when a type does not implement a method for any other reason.

The MSDN is even weaker on the subject, merely stating that, ‘The exception that is thrown when a requested method or operation is not implemented.’

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:38:57+00:00Added an answer on May 10, 2026 at 11:38 pm

    There is one situation I find it useful: TDD.

    I write my tests, then I create stubs so the tests compile. Those stubs do nothing but throw new NotImplementedException();. This way the tests will fail by default, no matter what. If I used some dummy return value, it might generate false positives. Now that all tests compile and fail because there is no implementation, I tackle those stubs.

    Since I never use a NotImplementedException in any other situation, no NotImplementedException will ever pass onto release code, since it will always make some test fail.

    You don’t need to catch it all over the place. Good APIs document the exceptions thrown. Those are the ones you should look for.

    EDIT: I wrote an FxCop rule to find them.

    This is the code:

    using System; using Microsoft.FxCop.Sdk;  /// <summary> /// An FxCop rule to ensure no <see cref='NotImplementedException'/> is /// left behind on production code. /// </summary> internal class DoNotRaiseNotImplementedException : BaseIntrospectionRule {     private TypeNode _notImplementedException;     private Member _currentMember;      public DoNotRaiseNotImplementedException()         : base('DoNotRaiseNotImplementedException',                // The following string must be the assembly name (here                // Bevonn.CodeAnalysis) followed by a dot and then the                // metadata file name without the xml extension (here                // DesignRules). See the note at the end for more details.                'Bevonn.CodeAnalysis.DesignRules',                typeof (DoNotRaiseNotImplementedException).Assembly) { }      public override void BeforeAnalysis()     {         base.BeforeAnalysis();         _notImplementedException = FrameworkAssemblies.Mscorlib.GetType(             Identifier.For('System'),             Identifier.For('NotImplementedException'));     }      public override ProblemCollection Check(Member member)     {         var method = member as Method;         if (method != null)         {             _currentMember = member;             VisitStatements(method.Body.Statements);         }         return Problems;     }      public override void VisitThrow(ThrowNode throwInstruction)     {         if (throwInstruction.Expression != null &&             throwInstruction.Expression.Type.IsAssignableTo(_notImplementedException))         {             var problem = new Problem(                 GetResolution(),                 throwInstruction.SourceContext,                 _currentMember.Name.Name);             Problems.Add(problem);         }     } } 

    And this is the rule metadata:

    <?xml version='1.0' encoding='utf-8' ?> <Rules FriendlyName='Bevonn Design Rules'>   <Rule TypeName='DoNotRaiseNotImplementedException' Category='Bevonn.Design' CheckId='BCA0001'>     <Name>Do not raise NotImplementedException</Name>     <Description>NotImplementedException should not be used in production code.</Description>     <Url>http://stackoverflow.com/questions/410719/notimplementedexception-are-they-kidding-me</Url>     <Resolution>Implement the method or property accessor.</Resolution>     <MessageLevel Certainty='100'>CriticalError</MessageLevel>     <Email></Email>     <FixCategories>NonBreaking</FixCategories>     <Owner></Owner>   </Rule> </Rules> 

    To build this you need to:

    • reference Microsoft.FxCop.Sdk.dll and Microsoft.Cci.dll

    • Put the metadata in a file called DesignRules.xml and add it as an embedded resource to your assembly

    • Name your assembly Bevonn.CodeAnalysis. If you want to use different names for either the metadata or the assembly files, make sure you change the second parameter to the base constructor accordingly.

    Then simply add the resulting assembly to your FxCop rules and take those damned exceptions out of your precious code. There are some corner cases where it won’t report a NotImplementedException when one is thrown but I really think you are hopeless if you’re actually writing such cthulhian code. For normal uses, i.e. throw new NotImplementedException();, it works, and that is all that matters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this really complex animation that runs once and I can not use
I find this really strange..could someone give an explanation? abstract class UIController{ public static
So I have this really large object that I use to control things in
This really seems like a bug to me, but perhaps some databinding gurus can
This really shouldn't be hard, I just can't figure out how to do it.
I've got this really simple piece of code that I thought was the correct
I've been having this really annoying thing happen the past few days, that has
I got this really cool Moq method that fakes out my GetService, looks like
I found this really nice function that receives your desired proportions and resizes/crops the
This really should be easy, but I just can't work it out myself, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.