<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eXclusiveMinds &#187; Exceptions</title>
	<atom:link href="http://eXclusiveMinds.com/tag/exceptions/feed/" rel="self" type="application/rss+xml" />
	<link>http://eXclusiveMinds.com</link>
	<description>eXclusive resource for programmers, developers and designers</description>
	<lastBuildDate>Sat, 13 Mar 2010 23:28:44 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Catching Unhandled Exceptions in C#</title>
		<link>http://eXclusiveMinds.com/2009/12/02/catching-unhandled-exceptions-in-c/</link>
		<comments>http://eXclusiveMinds.com/2009/12/02/catching-unhandled-exceptions-in-c/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 23:14:52 +0000</pubDate>
		<dc:creator>eXclusiveMinds</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Exceptions]]></category>

		<guid isPermaLink="false">http://eXclusiveMinds.com/?p=142</guid>
		<description><![CDATA[Following example demonstrates how we can manage all exception which are not caught by try-catch block.

To handle uncaught exceptions which are thrown by the UI thread use  UnhandledException event
To handle uncaught exception which are thrown by non-UI thread use ThreadException event

class Program
&#123;
    public static void Main&#40;string&#91;&#93; args&#41;
    &#123;
 [...]]]></description>
			<content:encoded><![CDATA[<p>Following example demonstrates how we can manage all exception which are not caught by try-catch block.<br />
<span id="more-142"></span></p>
<p>To handle uncaught exceptions which are thrown by the UI thread use  <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx">UnhandledException event</a></p>
<p>To handle uncaught exception which are thrown by non-UI thread use <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx">ThreadException event</a></p>

<div class="wp_syntax"><table><tr><td><div class="code"><pre class="csharp" style="font-family:Consolas; monospace;"><span style="color: #FF0000;">class</span> Program
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">//Enables Visual Styles</span>
        Application.<span style="color: #0000FF;">EnableVisualStyles</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Set default</span>
        Application.<span style="color: #0000FF;">SetCompatibleTextRenderingDefault</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Add event handller for Application Thread</span>
        Application.<span style="color: #0000FF;">ThreadException</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> ThreadExceptionEventHandler<span style="color: #000000;">&#40;</span>MyApplication_ThreadException<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Add event handler for Current domain </span>
        AppDomain.<span style="color: #0000FF;">CurrentDomain</span>.<span style="color: #0000FF;">UnhandledException</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> UnhandledExceptionEventHandler<span style="color: #000000;">&#40;</span>MyCurrentDomain_UnhandledException<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">//Start application</span>
        Application.<span style="color: #0000FF;">Run</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Form1<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> MyApplication_ThreadException<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, ThreadExceptionEventArgs ex<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        MessageBox.<span style="color: #0000FF;">Show</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">Exception</span>.<span style="color: #0000FF;">Message</span>, <span style="color: #666666;">&quot;Unhandled Thread Exception&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> MyCurrentDomain_UnhandledException<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, UnhandledExceptionEventArgs ex<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        MessageBox.<span style="color: #0000FF;">Show</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">ExceptionObject</span> <span style="color: #0600FF;">as</span> Exception<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Message</span>, <span style="color: #666666;">&quot;Unhandled UI Exception&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></td></tr></table></div>

<img src="http://eXclusiveMinds.Com/?ak_action=api_record_view&id=142&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://eXclusiveMinds.com/2009/12/02/catching-unhandled-exceptions-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
