<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>NotImplementedException vs. NotSupportedException</title><link>http://blogs.msdn.com/jaredpar/archive/2008/12/12/notimplementedexception-vs-notsupportedexception.aspx</link><description>In responding to a recent blog post , one of the readers, Jeremy Gray, noted that I was using a NotImplementedException where I should have been using a NotSupportedException .&amp;#160; At first I did not agree.&amp;#160; There was a method on an interface which</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: NotImplementedException vs. NotSupportedException</title><link>http://blogs.msdn.com/jaredpar/archive/2008/12/12/notimplementedexception-vs-notsupportedexception.aspx#9202640</link><pubDate>Fri, 12 Dec 2008 19:22:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9202640</guid><dc:creator>Keith Patrick</dc:creator><description>&lt;p&gt;I only use NotImplemented as a placeholder within stubs, so if I release code with a NotImplementedException, it means I forgot to finish my code (and in fact, VS2008 updated its &amp;quot;Generate Method Stub&amp;quot; functionality to throw that instead of just Exception(&amp;quot;This isn't implemented&amp;quot;))&lt;/p&gt;
</description></item><item><title>re: NotImplementedException vs. NotSupportedException</title><link>http://blogs.msdn.com/jaredpar/archive/2008/12/12/notimplementedexception-vs-notsupportedexception.aspx#9202698</link><pubDate>Fri, 12 Dec 2008 19:41:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9202698</guid><dc:creator>Jared Parsons</dc:creator><description>&lt;p&gt;@Keith,&lt;/p&gt;
&lt;p&gt;I've found one other case where NotImplementedException was appropriate. &amp;nbsp;Occassionally when implementing a very large COM interface, I only need it for a very small subset of the methods. &amp;nbsp;I know the component I hand the interface off to won't be using the other methods so there is no point in implementing them. &amp;nbsp;Instead I just throw a NotImplementedException. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;This is fairly rare though. &lt;/p&gt;
</description></item><item><title>re: NotImplementedException vs. NotSupportedException</title><link>http://blogs.msdn.com/jaredpar/archive/2008/12/12/notimplementedexception-vs-notsupportedexception.aspx#9222396</link><pubDate>Mon, 15 Dec 2008 23:43:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9222396</guid><dc:creator>Mark Brackett</dc:creator><description>&lt;p&gt;I tend to use NotSupported when the functionality will never be available. Usually, that's when it doesn't make &amp;quot;sense&amp;quot; to support it. Your example of Add on a ReadOnlyCollection is a good one. Brad Abrams[1] *suggests* (but doesn't explicitly state) that you should have a way of checking whether it will throw, but I'm not sure I see that as necessary (nice, yes - but necessary? I'm not convinced.)&lt;/p&gt;
&lt;p&gt;NotImplemented means that it *could* be implemented - it just hasn't been. It's either a work in progress, or I didn't think anyone would actually need it, etc.&lt;/p&gt;
&lt;p&gt;Both NotSupported and NotImplemented should *always* be thrown by a particular method - it should be the only thing in the method. If there's some object state with which you can't fulfill the contract, then you should use InvalidOperation. It *is* implemented - just that it's not available right now.&lt;/p&gt;
&lt;p&gt;[1] &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/brada/archive/2004/07/29/201354.aspx"&gt;http://blogs.msdn.com/brada/archive/2004/07/29/201354.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: NotImplementedException vs. NotSupportedException</title><link>http://blogs.msdn.com/jaredpar/archive/2008/12/12/notimplementedexception-vs-notsupportedexception.aspx#9222660</link><pubDate>Tue, 16 Dec 2008 01:38:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9222660</guid><dc:creator>Jeremy Gray</dc:creator><description>&lt;p&gt;I like that you make specific mention of the association with another property as it is a strong hint, but I, like Mark, would argue that one should also use NotSupportedException in any case where that member will never be implemented by a given implementation, even without an associated property. I have even bumped into this as a documented requirement for extension points, provider model implementations, etc. that I have encountered from third parties.&lt;/p&gt;
&lt;p&gt;I tend to summarize the most commonly-used options something like this: This member is not implemented yet but will be very soon = NotImplementedException. This member will never be implemented by this type = NotSupportedException. This member is already implemented but current instance state disallows its use = InvalidOperationException.&lt;/p&gt;
&lt;p&gt;From there you're off into Argument*Exception, etc. and the list becomes more obvious and correspondingly more tedious to reproduce. :)&lt;/p&gt;
&lt;p&gt;To me, seeing a given member in a codebase throwing NotImplementedException over a notable period of time is a warning sign, usually suggesting that implementation is required, less frequently suggesting that an entire interface should be dropped and/or that other class refactoring is needed, and least frequently suggesting that it should be changed to NotSupportedException, if only because NotSupportedExceptions should really appear only sparing within any given codebase (since the very existence of NotSupportedException and the patterns for which it is thrown suggests (to me, at least) one or more improperly factored interfaces and/or classes.)&lt;/p&gt;
&lt;p&gt;Jeremy&lt;/p&gt;
</description></item><item><title>re: NotImplementedException vs. NotSupportedException</title><link>http://blogs.msdn.com/jaredpar/archive/2008/12/12/notimplementedexception-vs-notsupportedexception.aspx#9222682</link><pubDate>Tue, 16 Dec 2008 01:50:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9222682</guid><dc:creator>Jared Parsons</dc:creator><description>&lt;p&gt;@Jeremy,&lt;/p&gt;
&lt;p&gt;I disagree about NotImplementedException mainly because of existing evidence. &amp;nbsp;Do a search in the BCL for uses of the empty NotImplementedException constructor. &amp;nbsp;I'm terrible at counting items in a visual list but I'd say there are 80+ uses of this constructor in the BCL libraries I currently have loaded in reflector. &amp;nbsp;Based on your definition of NotImplementedException it should not ever appear in an RTM library (unless I'm reading you wrong).&lt;/p&gt;
&lt;p&gt;The other case is COM libraries. &amp;nbsp;NotImplementedException is essentially a mapping of E_NOTIMPL into .Net (infact they translate to each other during COM interop). &amp;nbsp;If you find any non-trivial COM code base it will likely be literred with E_NOTIMPL. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Given that I would argue that NotImplementedException often represents a final state vs a transient one. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;It would be nice to have an exception that represented a transient state but I don't believe NotImplementedException could be relied on for this task. &amp;nbsp;&lt;/p&gt;
</description></item></channel></rss>