{"id":656,"date":"2010-08-22T16:13:22","date_gmt":"2010-08-22T15:13:22","guid":{"rendered":"http:\/\/www.gennard.net\/blog\/?p=656"},"modified":"2010-08-22T16:13:22","modified_gmt":"2010-08-22T15:13:22","slug":"dotnet-exceptions","status":"publish","type":"post","link":"http:\/\/www.gennard.net\/blog\/2010\/08\/dotnet-exceptions\/","title":{"rendered":""},"content":{"rendered":"<p>Last week I replied to a post about exceptions, it made me think those programming .Net daily take for granted the etiquette of using Exceptions.   So I thought I would share some of my thoughts&#8230; well it is a sort of a rules&#8217;ish list.<\/p>\n<ul>\n<li>Exceptions can be expensive, so avoid using them for normal conditions<\/li>\n<li>Only catch the exceptions you can handle<\/li>\n<li>Don&#8217;t hide\/swallow exceptions<\/li>\n<li>Don&#8217;t catch <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/System.Exception.aspx\">System.Exception<\/a> as will also catch unmanaged exceptions such as <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.runtime.interopservices.sehexception.aspx\">System.Runtime.InteropServices.SEHException<\/a><\/li>\n<li>Consider using your own custom exceptions or derive them from similar ones<\/li>\n<li>Remember inner exceptions when processing an exception\n<ul>\n<li>API&#8217;s such as MethodInfo.Invoke throw <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.reflection.targetinvocationexception.aspx\">TargetInvocationException<\/a> which contains the real exception<\/li>\n<\/ul>\n<\/li>\n<li>Use the Exception suffix on your custom exception<\/li>\n<li>Consider using Microsoft&#8217;s StyleCop to point out common issues<\/li>\n<li>Avoid using System.ApplicationException if you want to use the code in the Silverlight CLR<\/li>\n<li>Remember to serialize your own exception types<\/li>\n<li>Use xml comment docs for the exceptions a method raises&#8230; it helps intellisense..<\/li>\n<\/ul>\n<p>I suspect I might have missed something.. so feel free to comment..<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last week I replied to a post about exceptions, it made me think those programming .Net daily take for granted the etiquette of using Exceptions. So I thought I would share some of my thoughts&#8230; well it is a sort &hellip; <a href=\"http:\/\/www.gennard.net\/blog\/2010\/08\/dotnet-exceptions\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,32],"tags":[208,96,163],"_links":{"self":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/656"}],"collection":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/comments?post=656"}],"version-history":[{"count":0,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/posts\/656\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/media?parent=656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/categories?post=656"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gennard.net\/blog\/wp-json\/wp\/v2\/tags?post=656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}