<?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>What's wrong with this code? (#3) - Answer</title><link>http://blogs.msdn.com/b/ericgu/archive/2004/11/21/267690.aspx</link><description>Here's the discussion for the my last post . I liked Matthew's response: ...don't throw "Exception" since you are not supposed to catch "Exception." Anybody handling exceptions thrown by this code would have to catch Exception and ignore asynchronous</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Re:</title><link>http://blogs.msdn.com/b/ericgu/archive/2004/11/21/267690.aspx#333760</link><pubDate>Tue, 28 Dec 2004 12:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:333760</guid><dc:creator>RebelGeekz </dc:creator><description>[&lt;a target="_new" href="http://itpeixun.51.net/"&gt;http://itpeixun.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://aissl.51.net/"&gt;http://aissl.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz003.freewebpage.org/"&gt;http://kukuxz003.freewebpage.org/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz001.51.net/"&gt;http://kukuxz001.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz003.51.net/"&gt;http://kukuxz003.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz005.51.net/"&gt;http://kukuxz005.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz002.51.net/"&gt;http://kukuxz002.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz004.freewebpage.org/"&gt;http://kukuxz004.freewebpage.org/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz007.51.net/"&gt;http://kukuxz007.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz001.freewebpage.org/"&gt;http://kukuxz001.freewebpage.org/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz006.51.net/"&gt;http://kukuxz006.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz002.freewebpage.org/"&gt;http://kukuxz002.freewebpage.org/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz004.51.net/"&gt;http://kukuxz004.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz008.51.net/"&gt;http://kukuxz008.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz009.51.net/"&gt;http://kukuxz009.51.net/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz005.freewebpage.org/"&gt;http://kukuxz005.freewebpage.org/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz006.freewebpage.org/"&gt;http://kukuxz006.freewebpage.org/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz007.freewebpage.org/"&gt;http://kukuxz007.freewebpage.org/&lt;/a&gt;][&lt;a target="_new" href="http://kukuxz009.freewebpage.org/"&gt;http://kukuxz009.freewebpage.org/&lt;/a&gt;]&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=333760" width="1" height="1"&gt;</description></item><item><title>MBA</title><link>http://blogs.msdn.com/b/ericgu/archive/2004/11/21/267690.aspx#324616</link><pubDate>Sat, 18 Dec 2004 18:54:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:324616</guid><dc:creator>MBA</dc:creator><description>Helpful For MBA Fans.&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=324616" width="1" height="1"&gt;</description></item><item><title>re: What's wrong with this code? (#3) - Answer</title><link>http://blogs.msdn.com/b/ericgu/archive/2004/11/21/267690.aspx#271502</link><pubDate>Mon, 29 Nov 2004 12:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:271502</guid><dc:creator>David Levine</dc:creator><description>Actually, looking at the InnerException is also error prone...there's no guaranteee that there is a single InnerException as there is no limit to the number of catch-wrap-throw's that occurred, so there is no way to determine in advance which InnerException you should examine. If you really want to look at the root cause you can use e.GetBaseException(), but again, there's no guarantee that this will be what you want - the ultimate root cause may be a null reference which gets translated into a DatabaseException by a technical layer.&lt;br&gt;&lt;br&gt;This reinforces Eric's original point - if a method throws recoverable exceptions then it should be of a type other then System.Exception. It should be a specific type so that a caller is never forced to examine inner exceptions, only the outermost exception. The inner exceptions should provide context and clarify the situation.&lt;br&gt;&lt;br&gt;As a side note, one could also argue that this ambiguity reflects a fundamental weakness in the current exception model and its implementation.&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=271502" width="1" height="1"&gt;</description></item><item><title>re: What's wrong with this code? (#3) - Answer</title><link>http://blogs.msdn.com/b/ericgu/archive/2004/11/21/267690.aspx#270493</link><pubDate>Fri, 26 Nov 2004 00:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:270493</guid><dc:creator>Eric Newton</dc:creator><description>Simplest is best...&lt;br&gt;&lt;br&gt;if( e.InnerException is DatabaseException )&lt;br&gt;{ ... }&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=270493" width="1" height="1"&gt;</description></item><item><title>re: What's wrong with this code? (#3) - Answer</title><link>http://blogs.msdn.com/b/ericgu/archive/2004/11/21/267690.aspx#267770</link><pubDate>Mon, 22 Nov 2004 06:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:267770</guid><dc:creator>AT</dc:creator><description>Or the best one &lt;br&gt;if (e.InnerException is DatabaseException) ;-)&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=267770" width="1" height="1"&gt;</description></item><item><title>re: What's wrong with this code? (#3) - Answer</title><link>http://blogs.msdn.com/b/ericgu/archive/2004/11/21/267690.aspx#267768</link><pubDate>Mon, 22 Nov 2004 06:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:267768</guid><dc:creator>AT</dc:creator><description>Marcelo, &lt;br&gt;e.InnerException can be a null. &lt;br&gt;&lt;br&gt;Much better is &lt;br&gt;(typeof(DatabaseException).IsInstanceOfType(e.InnerException))&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=267768" width="1" height="1"&gt;</description></item><item><title>re: What's wrong with this code? (#3) - Answer</title><link>http://blogs.msdn.com/b/ericgu/archive/2004/11/21/267690.aspx#267705</link><pubDate>Mon, 22 Nov 2004 01:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:267705</guid><dc:creator>Marcelo</dc:creator><description>You might want to change&lt;br&gt;&lt;br&gt;if (e.InnerException.GetType() == typeof(DatabaseException))&lt;br&gt;&lt;br&gt;to&lt;br&gt;&lt;br&gt;if (typeof(DatabaseException).IsAssignableFrom(e.InnerException.GetType()))&lt;br&gt;&lt;br&gt;This lets the called code throw a DatabaseException subclass in the future with more information, if they so wish, without breaking your code. Exact type comparison is rarely what people need in most situations...&lt;br&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=267705" width="1" height="1"&gt;</description></item></channel></rss>