<?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>How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx</link><description>I still get a lot of questions on how to design exception hierarchies, despite several attempts to describe it in talks, the FDG book, and in posts on this blog. Maybe the guidance gets lots in the in the complexities of the full guidance surrounding</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#1561119</link><pubDate>Wed, 31 Jan 2007 06:22:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1561119</guid><dc:creator>Tom Kirby-Green</dc:creator><description>&lt;p&gt;Great post Krzysztof, the whole subject of good design of exceptions keeps coming up at my shop. You latest post helps no end, many thanks! :-)&lt;/p&gt;</description></item><item><title>How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#1561629</link><pubDate>Wed, 31 Jan 2007 08:17:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1561629</guid><dc:creator>The Visual Studio Code Analysis Team Blog</dc:creator><description>&lt;p&gt;Krzysztof Cwalina, owner of the Framework Design Guidelines , has written a great post on How to Design&lt;/p&gt;
</description></item><item><title>re: How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#1564613</link><pubDate>Wed, 31 Jan 2007 14:41:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1564613</guid><dc:creator>Thanuja</dc:creator><description>&lt;p&gt;Thanks KC for the post. &lt;/p&gt;
&lt;p&gt;I would like to know ur idea on following design. Think we have several framework components that fall in to several assemblies such as Caching, Data Access Framework, Configuration, etc. Then we create separate exception classes derived from System.Exception and place in each of the component, such as CachingException, DAException, etc. This type is used to wrap whatever the framework exceptions thrown from the framework APIs and throw/re-throw when necessary. &amp;nbsp;Since these components can be called in a hierarchical manner (DA calls Configuration, etc, ), I believe it would be easy to track from which component the exception is raised.&lt;/p&gt;
&lt;p&gt;Well would this design make sense?&lt;/p&gt;</description></item><item><title>re: How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#1567306</link><pubDate>Thu, 01 Feb 2007 00:32:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1567306</guid><dc:creator>Roman Korchagin</dc:creator><description>&lt;p&gt;Hi Krzysztof, grest post. We are an ISV and while we had no problems designing exceptions according to your guidelines, we are having a bit of a head scratch trying to document them in the public API. This is the question posted in my blog &lt;a rel="nofollow" target="_new" href="http://www.aspose.com/Community/blogs/aspose.words/archive/2007/01/27/66265.aspx"&gt;http://www.aspose.com/Community/blogs/aspose.words/archive/2007/01/27/66265.aspx&lt;/a&gt;. Thanks.&lt;/p&gt;</description></item><item><title>Exceptions thrown by Document constructors got better</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#1567665</link><pubDate>Thu, 01 Feb 2007 01:30:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1567665</guid><dc:creator>Aspose.Words</dc:creator><description>&lt;p&gt;According to many customers' requests we have improved design and documentation related to exceptions...&lt;/p&gt;
</description></item><item><title>re: How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#1572567</link><pubDate>Thu, 01 Feb 2007 15:37:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1572567</guid><dc:creator>Alfred Myers</dc:creator><description>&lt;p&gt;Thanuja,&lt;/p&gt;
&lt;p&gt;You can track the component that raised the exception from the stack trace every Exception provides. Is there any other reason for creating your custom exceptions?&lt;/p&gt;</description></item><item><title>Hierarquia de exce&amp;#231;&amp;#245;es</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#1572597</link><pubDate>Thu, 01 Feb 2007 15:43:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1572597</guid><dc:creator>How things (should) work</dc:creator><description>&lt;p&gt;O Krzysztof Cwalina (pronuncia-se cristof sualina) escreveu um post interessante sobre o projeto e uso...&lt;/p&gt;
</description></item><item><title>re: How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#1585897</link><pubDate>Sat, 03 Feb 2007 03:27:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1585897</guid><dc:creator>kcwalina</dc:creator><description>&lt;p&gt;Thanuja, I would not catch and wrap unless you have a good reason for doing it. Being able to track which component raised an exception is not a good reason IMHO; you can get this information from the callstack. A good reason is if you want to abstract the internal implementation. More on this below.&lt;/p&gt;
&lt;p&gt;Roman, documenting exceptions is hard. The reason is that it's actually not about just documenting exceptions, but more about being very explicit about the contract of the APIs. Specifying, describing, and keeping in compliance with contract requires deliberate design and takes time. But great reusable components must do it. The .NET framework does an ok job here and we are constantly thinking how to improve.&lt;/p&gt;
&lt;p&gt;As to the specific questions, I would definitely document all exceptions you end up throwing from your component, even the ones thrown from the lower layers (e.g. the Framework).&lt;/p&gt;
&lt;p&gt;But, I would be careful with letting implementation details leak through higher level abstractions. For example, you don't want to throw FileNotFoundException from database access APIs when the database is stored in a file. The fact that the data is stored in a file is an implementation detail that can change in the future. Same for things like configuration system APIs. The .NET config system is file based, but we don't (or at least I hope we don't) throw FileIO exceptions when the files get corrupted.&lt;/p&gt;
&lt;p&gt;Now, when you catch and abstract (throw a different exception), you need to ensure that you leave the system in a known state such that client code can now handle your abstracted exception. Is no good to catch, wrap/abstract, and retrow a different exception that cannot be handled anyway because it would leave the internal implementation in an undefined state.&lt;/p&gt;
</description></item><item><title>推薦一個很棒的 Design Blog. "Krzysztof Cwalina"</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#1665267</link><pubDate>Tue, 13 Feb 2007 03:57:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1665267</guid><dc:creator>Refines.Info["Polo Lee"]</dc:creator><description>&lt;p&gt;為什麼推薦 ? Krzysztof Cwalina 是 .NET Framework API Design Team 的 Program Manager, 他也寫了 一本 Framework Design&lt;/p&gt;
</description></item><item><title>re: How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#3140410</link><pubDate>Thu, 07 Jun 2007 15:35:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3140410</guid><dc:creator>vijay</dc:creator><description>&lt;p&gt;Hi Krzysztof, I am asking this question in a different context? how do you define hierarchies in business applicaitons? for e.g. if we have Customer related exceptions then should be have a base class like CustomerException and then let specific customer related exception inherit from this CustomerException like InvalidCustomerException? or there should be more generic BusinessException and for any conditions we throw this business exception. in consideration of Logging, I would like to have some specific business data to be logged. so considering this what are your suggestions for the hierarchy?&lt;/p&gt;</description></item><item><title>re: How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#3235091</link><pubDate>Mon, 11 Jun 2007 23:29:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3235091</guid><dc:creator>kcwalina</dc:creator><description>&lt;p&gt;Vijay, I think same guidelines apply to bussiness applications: create a new exception if you can articulate reasons for the existance of the exception beyond just wanting to create a hierarchy.&lt;/p&gt;
</description></item><item><title>re: How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#3521844</link><pubDate>Mon, 25 Jun 2007 18:38:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3521844</guid><dc:creator>Eran Nachum</dc:creator><description>&lt;P&gt;Great post, very enjoyed reading it and got a nice prespective about all this issue.&lt;/P&gt;
&lt;P&gt;I am inviting to take a look in my weblog at &lt;A href="http://www.eranachum.com/" target=_new rel=nofollow&gt;http://www.eranachum.com&lt;/A&gt;&lt;/P&gt;</description></item><item><title>re: How to Design Exception Hierarchies</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#9000710</link><pubDate>Wed, 15 Oct 2008 18:48:06 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9000710</guid><dc:creator>Peter Pohmann</dc:creator><description>&lt;p&gt;Hi Krzysztof,&lt;/p&gt;
&lt;p&gt;I am currently designing the exception hierarchy for our new product. I started out with the difference between recoverable exceptions and non-recoverable exceptions and ended up at pretty much the same pattern as you did.&lt;/p&gt;
&lt;p&gt;I would like to ask you about the SystemException class in the .NET framework. Is documented as &amp;quot;SystemException is thrown by the common language runtime when errors occur that are nonfatal and recoverable by user programs.&amp;quot; Which would mean that it corresponds to what you are calling logical errors.&lt;/p&gt;
&lt;p&gt;However, derived exceptions include ArrayTypeMismatchException, which is IMO a usage error and OutOfMemoryException, which is a system failure.&lt;/p&gt;
&lt;p&gt;So I conclude that the documentation is not really helpful here and that SystemException is not a good base class for custom logical errors.&lt;/p&gt;
&lt;p&gt;You said this implicitly already by advising to use Exception as the base class for such errors. &lt;/p&gt;
&lt;p&gt;Do you agree?&lt;/p&gt;</description></item><item><title>Why catch(Exception)/empty catch is bad</title><link>http://blogs.msdn.com/kcwalina/archive/2007/01/30/ExceptionHierarchies.aspx#9435093</link><pubDate>Fri, 20 Feb 2009 01:43:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9435093</guid><dc:creator>CLR Team Blog</dc:creator><description>&lt;p&gt;You’ve seen the advice before— it’s not a good programming practice to catch System.Exception . Because&lt;/p&gt;
</description></item></channel></rss>