TheChaseMan's Frenetic SoapBox

Always looking for better ways to do things...

Boo!!! Visual Studio 2005 Generates "throw new Exception"

Maybe Charles Petzold is more correct than I gave him credit for with my knee-jerk reaction. Using the RTM version of VS2005, I was writing some code to inherit from KeyedCollection from System.Collections.ObjectModel. KeyedCollection is abstract and there is an abstract method named GetKeyForItem which you must implement in your derived class. Using my very cool intellisense feature, I started typing the override and here's what it generated for me by default...

protected override int GetKeyForItem(int item)

{

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

}

Yuck! If you read the Framework Design Guidelines or the SLAR Volume 1, you'll see annotations that suggest that System.Exception should be treated like an abstract class. You should not throw System.Exception and you should almost never catch System.Exception. So why is the IDE throwing a System.Exception instead of a NotImplementedException? Boo!   :-)


Digg!

posted on Sunday, October 30, 2005 10:11 AM

Feedback

# re: Boo!!! Visual Studio 2005 Generates "throw new Exception" 12/8/2005 4:23 PM Anson Horton

I wrote a post that explains our thinking (and a workaround) http://blogs.msdn.com/ansonh/archive/2005/12/08/501763.aspx. Hope that helps!

Anson Horton [ansonh@microsoft.com]
Visual C# IDE PM

# re: Boo!!! Visual Studio 2005 Generates "throw new Exception" 12/8/2005 7:56 PM Sean Chase

Cool, thanks Anson! Cyrus explained to me why that happened and where the template was. It is still a bumber that everyone gets that behavior by default and a lot of us will end up working with people that never update the new template. :-)