{"id":109,"date":"2009-12-16T13:22:00","date_gmt":"2009-12-16T13:22:00","guid":{"rendered":"http:\/\/ashokaon.tech\/?p=109"},"modified":"2020-07-18T01:29:23","modified_gmt":"2020-07-17T19:59:23","slug":"debug-exceptions-window","status":"publish","type":"post","link":"https:\/\/ashokaon.tech\/blog\/debug-exceptions-window\/","title":{"rendered":"The (not much utilized) Debug->Exceptions\u2026 window technique"},"content":{"rendered":"<p><span style=\"font-size: 10px;background-color:#FFFF99;display:block\">(Note: This blog post was originally published under my old domain(codesmiles.com), <a href=\"http:\/\/codesmiles.com\/post\/Debug-Exceptions-window.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. <a href=\"https:\/\/web.archive.org\/web\/2010*\/http:\/\/www.codehappiness.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Web Archive link<\/a>.<\/span><br \/>\nThe <strong>Debug-Exceptions\u2026<\/strong> window is a useful tool that at times saves lot of time when debugging. Even though this exists (i think)from Visual Studio 2003, I Still find people struggle a bit with the situation I am going to explain next.[more]<\/p>\n<p>As you know Visual Studio highlights the exception code line when it is not handled. Sometimes we purposely don\u2019t handle exceptions in a method and let the exception thrown to calling functions.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"filenotfound1\" src=\"\/blog\/wp-content\/uploads\/filenotfound1_thumb.png\" border=\"0\" alt=\"filenotfound1\" width=\"504\" height=\"308\"><\/p>\n<p>&nbsp;<\/p>\n<p>Usually we have a multi-project solution that typically has layers like Business logic, Data access layer, UI, etc. Imagine that you make a call from the UI to a local function and it calls another function in BLL and the call goes deep into layers of your project architecture.<\/p>\n<p>Now, when it is not sure if each of the methods getting called handles exceptions in it or doesn&#8217;t throw identifiable exceptions.<\/p>\n<p>For instance..<\/p>\n<p>private void Function_A()<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp; try<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BLLFunction();\/\/this calls few other functions..<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp; catch (Exception ex)<br \/>\n&nbsp;&nbsp;&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/handle exception<br \/>\n&nbsp;&nbsp;&nbsp; }<br \/>\n}<\/p>\n<p>Function_A() calls BLLFunction() and it again calls few other functions, but I have handled exceptions only in Function_A(). In this case, whatever method in the call hierarchy triggers an exception, the Visual Studio debugger takes the control to the <strong>catch()<\/strong> in Function_A(). Debugging this could be bit hard when the number of functions is more and code is complex. You have to narrow down to the function and line the exception occurred.<\/p>\n<p>Instead, a simple technique can be performed with the Debug-Exceptions window&#8230;<\/p>\n<p>If you choose <strong>Debug \u2013&gt; Exceptions\u2026<\/strong> a window appears with various categories of exceptions. Check the <strong>Thrown<\/strong> check box beside <strong>Common Language Runtime Exceptions<\/strong>,<strong> <\/strong>and now if you re-debug the project, the line highlighted by debugger will be the exact line where the exception occurs in the exception triggering method.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"debug-exceptions\" src=\"\/blog\/wp-content\/uploads\/debug-exceptions_thumb.png\" border=\"0\" alt=\"debug-exceptions\" width=\"627\" height=\"318\"><\/p>\n<p>What happens is, we specify that all Common Language Exceptions are <strong>Thrown<\/strong> regardless of whether it is handled or not.<\/p>\n<p>You can even set only the exception you want to be thrown by selecting the exception using the <strong>Find..<\/strong> option as below, this will only throw that specific exception even if it is handled elsewhere and ignore other exceptions.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" title=\"debug-exceptions1\" src=\"\/blog\/wp-content\/uploads\/debug-exceptions1_thumb.png\" border=\"0\" alt=\"debug-exceptions1\" width=\"474\" height=\"284\"><\/p>\n<p>The <em>User-unhandled<\/em> option seems bit unclear as of now, and couldn\u2019t put time to find a clear usage scenario now, but thought the above is useful enough to write.<\/p>\n<p style=\"letter-spacing:0.5px\"><em>If you like this article..<\/em><\/p>\n<p><a style=\"border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" href=\"http:\/\/www.dotnetkicks.com\/kick\/?url=http%3a%2f%2fwww.codehappiness.com%2fpost%2fDebug-Exceptions-window.aspx\"><img decoding=\"async\" style=\"vertical-align:middle;\" src=\"http:\/\/www.dotnetkicks.com\/Services\/Images\/KickItImageGenerator.ashx?url=http%3a%2f%2fwww.codehappiness.com%2fpost%2fDebug-Exceptions-window.aspx\" border=\"0\" alt=\"kick it on DotNetKicks.com\"><\/a>&nbsp;&nbsp;&nbsp;   <a style=\"border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px\" rev=\"vote-for\" href=\"http:\/\/dotnetshoutout.com\/The-Debug-Exceptions-window-technique\"><img decoding=\"async\" style=\"vertical-align:middle;\" src=\"http:\/\/dotnetshoutout.com\/image.axd?url=http%3A%2F%2Fwww.codehappiness.com%2Fpost%2FDebug-Exceptions-window.aspx\" border=\"0\" alt=\"Shout it\"><\/a><\/p>\n<p style=\"padding:5px 0 0 7px\">\n<script type=\"text\/javascript\"><!--\ntweetmeme_url = 'http:\/\/www.codesmiles.com\/post\/Debug-Exceptions-window.aspx';\n\/\/ --><\/script><br \/>\n<script src=\"http:\/\/tweetmeme.com\/i\/scripts\/button.js\" type=\"text\/javascript\"><\/script><\/p>\n<p>&nbsp;<\/p>\n<div class=\"pflink\">\n<ul>\n<li><a title=\"Click to Subscribe\" href=\"http:\/\/feeds.feedburner.com\/codehappiness\"> <img decoding=\"async\" class=\"pflinkfeed\" src=\"http:\/\/www.codesmiles.com\/pics\/feed-icon-16x16.png\" alt=\"RSS feed\"><\/a>&nbsp;<span><a title=\"Click to Subscribe\" href=\"http:\/\/feeds.feedburner.com\/codehappiness\">Subscribe to the feed!<\/a> (<a href=\"http:\/\/www.codesmiles.com\/post\/what-is-an-rss-feed.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">?<\/a>) and receive any such future posts on your favorite <a href=\"http:\/\/www.codesmiles.com\/post\/what-is-an-rss-feed.aspx\" target=\"_blank\" rel=\"noopener noreferrer\">feed reader<\/a><\/span><\/li>\n<li>Any comments? <a title=\"Comments can be used to express your thoughts about this blog entry\" rel=\"nofollow\" href=\"http:\/\/www.codesmiles.com\/post\/Debug-Exceptions-window.aspx#befcomment\">write here<\/a>..<\/li>\n<\/ul>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"font-size: 11px\">\n<p>I have posted this blog entry as article in <a rel=\"tag\" href=\"http:\/\/www.codeproject.com\">CodeProject<\/a> too.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(Note: This blog post was originally published under my old domain(codesmiles.com), here. Web Archive link. The Debug-Exceptions\u2026 window is a useful tool that at times saves lot of time when debugging. Even though this exists (i think)from Visual Studio 2003, I Still find people struggle a bit with the situation<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[32,17,28,31],"_links":{"self":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts\/109"}],"collection":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/comments?post=109"}],"version-history":[{"count":5,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts\/109\/revisions"}],"predecessor-version":[{"id":321,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/posts\/109\/revisions\/321"}],"wp:attachment":[{"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/media?parent=109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/categories?post=109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ashokaon.tech\/blog\/wp-json\/wp\/v2\/tags?post=109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}