{"id":275,"date":"2005-09-20T14:07:04","date_gmt":"2005-09-20T20:07:04","guid":{"rendered":"http:\/\/jameskovacs.com\/2005\/09\/20\/Catching+Exceptions+In+Windows+Forms+Apps"},"modified":"2005-09-20T14:07:04","modified_gmt":"2005-09-20T20:07:04","slug":"catching-exceptions-in-windows-forms-apps","status":"publish","type":"post","link":"https:\/\/www.jameskovacs.com\/index.php\/2005\/09\/20\/catching-exceptions-in-windows-forms-apps\/","title":{"rendered":"Catching Exceptions in Windows Forms apps"},"content":{"rendered":"<p><P>Another thing that&#8217;s been kicking around for awhile and I figured it was time to persist to long-term storage. Here are the three top-level places in a WinForms app where you absolutely need exception handling routines to ensure that all exceptions are caught:<\/P><br \/>\n<OL><br \/>\n<LI>try\/catch around Main()<br \/>\n<LI>Attach a System.Threading.ThreadExceptionEventHandler to Application.ThreadException<br \/>\n<LI>Attach a UnhandledExceptionEventHandler to AppDomain.CurrentDomain.UnhandledException<\/LI><\/OL><br \/>\n<P>Note that simply having a try\/catch around Main() is insufficient as you will not catch exceptions that occur during the execution of event handlers or asynchronous callbacks.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Another thing that&#8217;s been kicking around for awhile and I figured it was time to persist to long-term storage. Here are the three top-level places in a WinForms app where you absolutely need exception handling routines to ensure that all exceptions are caught: try\/catch around Main() Attach a System.Threading.ThreadExceptionEventHandler to Application.ThreadException Attach a UnhandledExceptionEventHandler to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,27],"tags":[],"class_list":["post-275","post","type-post","status-publish","format-standard","hentry","category-dotnetgeneral","category-winforms"],"_links":{"self":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/comments?post=275"}],"version-history":[{"count":0,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/media?parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/categories?post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/tags?post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}