<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Back to Basics</title>
        <link>http://rickgaribay.net/category/18.aspx</link>
        <description>Back to Basics</description>
        <language>en-US</language>
        <copyright>Rick G. Garibay</copyright>
        <managingEditor>rick@rickgaribay.net</managingEditor>
        <generator>Subtext Version 1.9.5.176</generator>
        <item>
            <title>Back to Basics: Exception Handling</title>
            <link>http://rickgaribay.net/archive/2007/11/07/back-to-basics-exception-handling.aspx</link>
            <description>&lt;p&gt;The .NET Framework is vast, and there are many aspects of the framework that are used every day by developers while others start to collect dust on the knowledge shelf. &lt;/p&gt;
&lt;p&gt;I consider myself a generalizing specialist, which in short means that when it comes to .NET, I've been there and done that, but I am currently focused on middle-tier and SOA architecture, design and development. From time to time, I find myself having to shake the cobwebs loose on some pretty fundamental features in the framework, so I am going to start up a new post category called "Back to Basics" to help new and seasoned folks alike (not to mention to document this stuff so I can look it up again later when I forget again).&lt;/p&gt;
&lt;p&gt;Recently, I found myself pondering exception handling behavior with custom exceptions. Fortunately, I hit my friend and collegue John Bierman, a Senior Consultant from Neudesic up and he set me straight:&lt;/p&gt;
&lt;p&gt;If you catch a custom exception in a generic exception catch block in a middle tier component – i.e. catch(Exception ex) – and then:&lt;/p&gt;
&lt;p class="MsoListParagraph" style="MARGIN-LEFT: 38.25pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Issue the “throw” command, the exception &lt;em&gt;will&lt;/em&gt; be propagated to the preceding method call as the custom exception…you will not lose the fact that it’s a custom exception and you will keep the original stack trace of the custom exception.&lt;/p&gt;
&lt;p class="MsoListParagraph" style="MARGIN-LEFT: 38.25pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Issue the “throw ex” command, the exception &lt;em&gt;will&lt;/em&gt; be propagated to the preceding method call as the custom exception… you will not lose the fact that it’s a custom exception *&lt;strong&gt;but&lt;/strong&gt;* you will lose the original stack trace. The new stack trace will look as though the exception originated from the location that issued the “throw ex”.&lt;/p&gt;
&lt;p class="MsoListParagraph" style="MARGIN-LEFT: 38.25pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;&lt;span style="FONT-FAMILY: Symbol; mso-fareast-font-family: Symbol; mso-bidi-font-family: Symbol"&gt;&lt;span style="mso-list: Ignore"&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;         &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Issue the “throw new Exception(ex.message, ex.innerException)” command, the exception &lt;em&gt;will *&lt;strong&gt;not&lt;/strong&gt;*&lt;/em&gt; be propagated to the preceding method call as the custom exception, its type will be a generic Exception… you *&lt;strong&gt;will&lt;/strong&gt;* lose the fact that it’s a custom exception.&lt;/p&gt;
&lt;p class="MsoListParagraph" style="MARGIN-LEFT: 38.25pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt; &lt;/p&gt;
&lt;p class="MsoListParagraph" style="MARGIN-LEFT: 38.25pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1"&gt;Good stuff!&lt;/p&gt;&lt;img src="http://rickgaribay.net/aggbug/163.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Rick G. Garibay - The more I learn, the less I kno</dc:creator>
            <guid>http://rickgaribay.net/archive/2007/11/07/back-to-basics-exception-handling.aspx</guid>
            <pubDate>Wed, 07 Nov 2007 16:47:10 GMT</pubDate>
            <wfw:comment>http://rickgaribay.net/comments/163.aspx</wfw:comment>
            <comments>http://rickgaribay.net/archive/2007/11/07/back-to-basics-exception-handling.aspx#feedback</comments>
            <wfw:commentRss>http://rickgaribay.net/comments/commentRss/163.aspx</wfw:commentRss>
            <trackback:ping>http://rickgaribay.net/services/trackbacks/163.aspx</trackback:ping>
        </item>
    </channel>
</rss>