<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Shiman's Weblog</title>
	<atom:link href="http://shiman.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://shiman.wordpress.com</link>
	<description>Collecting stones from the sea-shore.</description>
	<lastBuildDate>Mon, 02 Mar 2009 05:40:01 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='shiman.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/a18a2f4d1ebf931bc6d2c52ccf3d9d8a?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Shiman's Weblog</title>
		<link>http://shiman.wordpress.com</link>
	</image>
			<item>
		<title>C# .NET Reflection : Obtaining a Type Object with Object.GetType()</title>
		<link>http://shiman.wordpress.com/2009/02/12/c-net-reflection-obtaining-a-type-object-with-objectgettype/</link>
		<comments>http://shiman.wordpress.com/2009/02/12/c-net-reflection-obtaining-a-type-object-with-objectgettype/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 09:38:40 +0000</pubDate>
		<dc:creator>shiman</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Programming — Tags: .Net]]></category>
		<category><![CDATA[Reflection]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://shiman.wordpress.com/?p=318</guid>
		<description><![CDATA[We can obtain an instance of the Type class in a variety of ways. However, the one thing we cannot do is directly create a Type object using the new keyword, as Type is an abstract class. The Object.GetType method, the typeof operator, and various methods of the Assembly object return a Type object. GetType [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=318&subd=shiman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">We can obtain an instance of the <em><span>Type</span></em><span> </span>class in a variety of ways. However, the one thing we cannot do is directly create a <em><span>Type</span></em><span> </span>object using the <span>new </span>keyword, as <em><span>Type</span></em><span> </span>is an abstract class. The <em>Object.GetType</em> method, the <em>typeof</em> operator, and various methods of the <em>Assembly</em> object return a <em>Type</em> object.<em> GetType</em> is a member of the <em>Object</em> class, which is the ubiquitous base class. Therefore, <em>GetType</em> is inherited by .NET types and available to all managed instances. Each instance can call <em>GetType</em> to return the related <em>Type</em> object. The <em>typeof</em> operator extracts a <em>Type</em> object directly from a reference or value type. Assembly objects have several members that return one or more <em>Type</em> objects. For example, the <em>Assembly.GetTypes</em> method enumerates and returns the <em>Types</em> of the target assembly.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">As a member base class object, <em>GetType</em> is accessible to all instances of reference and values types. <em>GetType</em> returns the <em>Type</em> object of the instance. This is the syntax of the <em>GetType</em> method:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Type GetType()</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The following code creates instances of a value and a reference type, which are passed individually as object parameters to successive calls to the <em>DisplayType</em> method, which homogenizes the objects, where each object loses its distinction. The function extracts the type of the instance and displays the <em>Type</em> name. Finally, if the <em>Type</em> represents a <em>MyClass</em>, the <em>MyClass.Display</em> method is called:</span></p>
<pre class="brush: csharp;">using System;

namespace Examples.Reflection
{
    class Program
    {
        static void Main()
        {
            int value = 5;
            MyClass obj = new MyClass();
            DisplayType(value);
            DisplayType(obj);

            Console.ReadKey();
        }

        static void DisplayType(object parameterObject)
        {
            Type parameterType = parameterObject.GetType();
            string name = parameterType.Name;
            Console.WriteLine(&quot;Type is &quot; + name);

            if (name == &quot;MyClass&quot;)
            {
                ((MyClass)parameterObject).Display();
            }
        }
    }

    class MyClass
    {
        public void Display()
        {
            Console.WriteLine(&quot;MyClass &gt; Display&quot;);
        }
    }
}</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiman.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiman.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiman.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiman.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiman.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiman.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiman.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiman.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiman.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiman.wordpress.com/318/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=318&subd=shiman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shiman.wordpress.com/2009/02/12/c-net-reflection-obtaining-a-type-object-with-objectgettype/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Shiman</media:title>
		</media:content>
	</item>
		<item>
		<title>C# .NET Exception : AppDomain.UnhandledException</title>
		<link>http://shiman.wordpress.com/2008/11/18/c-net-exception-appdomainunhandledexception/</link>
		<comments>http://shiman.wordpress.com/2008/11/18/c-net-exception-appdomainunhandledexception/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 06:31:08 +0000</pubDate>
		<dc:creator>shiman</dc:creator>
				<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://shiman.wordpress.com/?p=314</guid>
		<description><![CDATA[When an unhandled exception is manifested in a Console application, the AppDomain .UnhandledException is raised. Subscribe to the event to clean up the resources of the application, such as closing files and relinquishing data connections. You might also record the unhandled exception in the event log or another location. It is important to note that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=314&subd=shiman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">When an unhandled exception is manifested in a Console application, the <em>AppDomain</em> <em>.UnhandledException</em> is raised. Subscribe to the event to clean up the resources of the application, such as closing files and relinquishing data connections. You might also record the unhandled exception in the event log or another location. It is important to note that the exception is not caught in the <em>AppDomain.UnhandledException</em> handler. After the handler finishes, the unhandled exception causes the application to be terminated. The <em>AppDomain.UnhandledException</em> event is triggered only in the initial application domain; it is ignored in other application domains.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><a name="778"></a><a name="IDX-350"></a><span style="font-size:small;font-family:Calibri;">Subscribe to the <em>AppDomain.UnhandledException</em> event with an <em>UnhandledExceptionEventHandler</em> delegate. The delegate has two parameters. The <em>object</em> parameter is the <em>AppDomain</em> object of the initial application domain. The <em>UnhandledExceptionEventArgs</em> parameter contains the specifics of the unhandled exception. This is the syntax of the <em>UnhandledExceptionEventHandler</em>:</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em>UnhandledExceptionEventHandler</em> syntax:</span></span></p>
<ul>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e)</span></div>
</li>
</ul>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em>UnhandledExceptionEventArgs</em> offers the <em>IsTerminating</em> and <em>ExceptionObject</em> properties. <em>IsTerminating</em> is a Boolean property indicating the status of the application. If true, the application is terminating because of the exception. If false, the application survives the exception. In .NET 2.0, this property is always true. Unhandled exceptions on both managed and unmanaged threads terminate an application. This is cleaner than the .NET 1.1 unhandled exception model, where exceptions raised on managed threads were nonfatal. The <em>Exception</em> property is an exception object for the unhandled exception. Inexplicably, this property is an object type, not an Exception type. Cast the property to the Exception type to access the details of the exception.</span></span></p>
<p><span style="font-size:small;"><span style="font-family:Calibri;"></p>
<p class="MsoNormal" style="margin:0 0 10pt;">In the following Console application, the <em>OnUnhandledException</em> method is added to the <em>AppDomain.UnhandledException</em> event. When the subsequent divide by zero exception occurs, the <em>OnUnhandledException</em> method is called.</p>
<p></span></span></p>
<pre class="brush: csharp;">using System;

namespace Examples.Exceptions
{
    public class Program
    {
        public static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException +=
                new UnhandledExceptionEventHandler(
                    OnUnhandledException);

            int vara = 5, varb = 0;
            vara /= varb;

            Console.ReadKey();
        }

        public static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            string application_name = sender.ToString();
            Exception except = (Exception)e.ExceptionObject;
            string errormessage = &quot;Application &quot; + application_name + &quot; [ Exception &quot; + except.Message + &quot; ]&quot;;
            Console.WriteLine(errormessage);
        }
    }
}</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiman.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiman.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiman.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiman.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiman.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiman.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiman.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiman.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiman.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiman.wordpress.com/314/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=314&subd=shiman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shiman.wordpress.com/2008/11/18/c-net-exception-appdomainunhandledexception/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Shiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Log4Net Cofiguration</title>
		<link>http://shiman.wordpress.com/2008/11/13/log4net-cofiguration/</link>
		<comments>http://shiman.wordpress.com/2008/11/13/log4net-cofiguration/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 07:00:38 +0000</pubDate>
		<dc:creator>shiman</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[S/W Engineering]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://shiman.wordpress.com/?p=308</guid>
		<description><![CDATA[I had to post this one long days ago as I promised in one of my earlier post about Log4Net. Sorry for this late. I am not a man of words. Thanks to Chris, for reminding me about this post. There are lots of things in the configuration of Log4Net. I will only about the commonly used sections.
&#60;log4net&#62;
	&#60;appender [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=308&subd=shiman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I had to post this one long days ago as I promised in one of my <a title="How to Log" href="http://shiman.wordpress.com/2008/07/09/how-to-log-in-c-net-with-log4net-a-tutorial">earlier post</a> about Log4Net. Sorry for this late. I am not a man of words. Thanks to Chris, for reminding me about this post. There are lots of things in the configuration of Log4Net. I will only about the commonly used sections.</p>
<pre class="brush: csharp;">&lt;log4net&gt;
	&lt;appender name=&quot;LogFileAppender&quot; type=&quot;log4net.Appender.FileAppender&quot;&gt;
		&lt;param name=&quot;File&quot; value=&quot;D:\Temp\ApplicationLog.log&quot; /&gt;
		&lt;param name=&quot;AppendToFile&quot; value=&quot;true&quot; /&gt;
		&lt;layout type=&quot;log4net.Layout.PatternLayout&quot;&gt;
			&lt;param name=&quot;Header&quot; value=&quot;&quot; /&gt;
			&lt;param name=&quot;Footer&quot; value=&quot;&quot; /&gt;
			&lt;param name=&quot;ConversionPattern&quot; value=&quot;%d [%t] %-5p %m%n&quot; /&gt;
		&lt;/layout&gt;
	&lt;/appender&gt;
	&lt;appender name=&quot;ConsoleAppender&quot; type=&quot;log4net.Appender.ConsoleAppender&quot; &gt;
		&lt;layout type=&quot;log4net.Layout.PatternLayout&quot;&gt;
			&lt;param name=&quot;Header&quot; value=&quot;[Header]\r\n&quot; /&gt;
			&lt;param name=&quot;Footer&quot; value=&quot;[Footer]\r\n&quot; /&gt;
			&lt;param name=&quot;ConversionPattern&quot; value=&quot;%d [%t] %-5p %m%n&quot; /&gt;
		&lt;/layout&gt;
	&lt;/appender&gt;
	&lt;root&gt;
		&lt;level value=&quot;DEBUG&quot; /&gt;
		&lt;appender-ref ref=&quot;LogFileAppender&quot; /&gt;
		&lt;appender-ref ref=&quot;ConsoleAppender&quot; /&gt;
	&lt;/root&gt;
&lt;/log4net&gt;</pre>
<p>Log4Net is configured in the configuration section &#8220;log4net&#8221;, specified with the tag &lt;log4net&gt;. Under this tag, you can find two tags, &lt;appender&gt; and &lt;root&gt;. (There could be more actually. but I did not need them yet.)</p>
<p>&lt;appender&gt; section says where and how the log should be written. It could be in the console, in a file, or database. Logs can even be sent to an email address. So, depending on you needs, you have to configure the appender. Under &lt;log4net&gt; element one or more appenders can be defined. I am interested to describe some of the appenders. Please remind me if I forget to do so.</p>
<p>&lt;root&gt; section is to say, which appender will be used to log, and what types of log will be written.<span style="word-spacing:0;font:13px/16px Verdana;text-transform:none;color:#000000;text-indent:0;white-space:normal;letter-spacing:normal;border-collapse:separate;orphans:2;widows:2;">Only one root logger element may only be defined and it must be a child of<span> </span><span class="code">&lt;log4net&gt;</span><span> </span>element.</span> To define te log-level, you have to specify your desired log-level in the &lt;level&gt; element. You can set the &#8216;value&#8217; attribute to any of the five log-levels. The levels are as follows hierarchically:</p>
<ol>
<li>FATAL</li>
<li>ERROR</li>
<li>WARN</li>
<li>INFO</li>
<li>DEBUG</li>
</ol>
<p>Once you specify the level of the log in the &#8216;value&#8217; attribute, logs for that level and the levels above will be written.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiman.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiman.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiman.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiman.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiman.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiman.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiman.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiman.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiman.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiman.wordpress.com/308/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=308&subd=shiman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shiman.wordpress.com/2008/11/13/log4net-cofiguration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Shiman</media:title>
		</media:content>
	</item>
		<item>
		<title>C# .NET Exceptions : Application.ThreadException</title>
		<link>http://shiman.wordpress.com/2008/11/12/c-net-exceptions-applicationthreadexception/</link>
		<comments>http://shiman.wordpress.com/2008/11/12/c-net-exceptions-applicationthreadexception/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 11:44:54 +0000</pubDate>
		<dc:creator>shiman</dc:creator>
				<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://shiman.wordpress.com/?p=304</guid>
		<description><![CDATA[In a Windows Forms application, the windows procedure raises the Application.ThreadException event upon an unhandled exception. Subscribe to the ThreadException event to handle the unhandled exception. The subscriber is an exception handler, which prevents the application from being terminated. Do not propagate an exception caught in this manner in the unhandled exception handler. The new [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=304&subd=shiman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">In a Windows Forms application, the windows procedure raises the <em>Application.ThreadException</em> event upon an unhandled exception. Subscribe to the <em>ThreadException</em> event to handle the unhandled exception. The subscriber is an exception handler, which prevents the application from being terminated. Do not propagate an exception caught in this manner in the unhandled exception handler. The new exception is unprotected and will likely terminate the application. After the unhandled exception handler completes, execution continues at the next message in the message pump.</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><a name="776"></a><a name="IDX-349"></a><span><span style="font-size:small;"><span style="font-family:Calibri;">Subscribe to the <em>ThreadException</em> event with a <em>ThreadExceptionEventHandler</em> delegate, which has two parameters. The object parameter is the thread object of the thread that raised the exception. The <em>ThreadExceptionEventArg</em> parameter of the <em>System.Threading</em> namespace contains the exception that was unhandled. This is the signature of the <em>ThreadExceptionEventHandler</em>:</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>ThreadExceptionEventHandler</span></em><span> syntax:</span></span></span></p>
<pre class="brush: csharp;">void ThreadExceptionEventHandler(object sender, ThreadExceptionEventArgs e)</pre>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><span><span style="font-size:11pt;line-height:115%;font-family:&quot;">In the following code, the <em>OnThreadException</em> handler is added to the <em>ThreadException</em> event. The <em>bthException_Click</em> method raises an unhandled divide by zero exception. The unhandled exception is then handled in the <em>OnThreadException</em> method, which displays an informative message. Run the application in release mode for the expected results. Otherwise, the Visual Studio debugger intercedes the exception.</span></span></span></span></p>
<pre class="brush: csharp;">private void btnException_Click(object sender, EventArgs e)
{
    int vara = 5, varb = 0;
    vara /= varb;
}

private void Form1_Load(object sender, EventArgs e)
{
    Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(OnThreadException);
}

void OnThreadException(object sender, ThreadExceptionEventArgs e)
{
    Thread t = (Thread)sender;
    Exception threadexception = e.Exception;
    string errormessage = &quot;Thread ID: &quot; + t.ManagedThreadId.ToString() + &quot; [ &quot; + threadexception.Message + &quot; ]&quot;;
    MessageBox.Show(errormessage);
}</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiman.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiman.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiman.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiman.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiman.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiman.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiman.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiman.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiman.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiman.wordpress.com/304/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=304&subd=shiman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shiman.wordpress.com/2008/11/12/c-net-exceptions-applicationthreadexception/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Shiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Why Log4Net?</title>
		<link>http://shiman.wordpress.com/2008/11/06/why-log4net/</link>
		<comments>http://shiman.wordpress.com/2008/11/06/why-log4net/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 09:54:43 +0000</pubDate>
		<dc:creator>shiman</dc:creator>
				<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[S/W Engineering]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://shiman.wordpress.com/?p=299</guid>
		<description><![CDATA[Microsoft has its own application block for logging. So, why should we use Log4Net instead of that?
Log4Net has some advantages over Enterprise Library Logging Application Block. These made Log4Net more preferable.
Works with .NET 1.0 &#38; 1.1 - The much improved logging of EntLib 2.0 and above is only available if your application is running on .NET [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=299&subd=shiman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal" style="margin:0 0 10pt;"><strong><span style="font-size:small;"><span style="font-family:Calibri;">Microsoft has its own application block for logging. So, why should we use Log4Net instead of that?</span></span></strong></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Log4Net has some advantages over Enterprise Library Logging Application Block. These made Log4Net more preferable.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><strong><span>Works with .NET 1.0 &amp; 1.1</span></strong><span> - The much improved logging of EntLib 2.0 and above is only available if your application is running on .NET 2.0 or greater. log4net however works on all versions of .NET.</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><strong><span>Simpler install</span></strong><span> - When using the Enterprise Library there are some services you really should install. This is as simple as running a bat file included with EntLib but it does complicate your deployment process.</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><strong><span>Slightly faster</span></strong><span> - log4net was significantly quicker than EntLib 1.1 logging. EntLib 2.0 onwards has improved its performance but log4net remains slightly faster. A benchmark I found while researching my presentation had EntLib taking approximately 5-6 seconds to log 100,000 entries while log4net took about 3 seconds. Does the speed difference matter? Probably not. However log4net net does support&#8230;</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><strong><span>Appender Buffering</span></strong><span> - Buffering support with some appenders lets log4net queue up log entries and write them in a single go. If you are writing entries to the database then buffering is a good way to improve performance.</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><strong><span>More platforms</span></strong><span> - Enterprise Library does not support the .NET Compact Framework while log4net does.</span></span></span></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiman.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiman.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiman.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiman.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiman.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiman.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiman.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiman.wordpress.com/299/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiman.wordpress.com/299/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiman.wordpress.com/299/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=299&subd=shiman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shiman.wordpress.com/2008/11/06/why-log4net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Shiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Remote Exceptions in C# .NET</title>
		<link>http://shiman.wordpress.com/2008/11/06/remote-exceptions-in-c-net/</link>
		<comments>http://shiman.wordpress.com/2008/11/06/remote-exceptions-in-c-net/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 08:36:36 +0000</pubDate>
		<dc:creator>shiman</dc:creator>
				<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://shiman.wordpress.com/?p=297</guid>
		<description><![CDATA[Exceptions sometime occur in remote code. An exception that is raised in a different application domain is a remote exception. Remote exceptions include exceptions thrown in a .NET Remoting application or a Web service application. Exceptions that cross application domains must be serialized to maintain the state. System exceptions are serializable. However, you need to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=297&subd=shiman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Exceptions sometime occur in remote code. An exception that is raised in a different application domain is a remote exception. Remote exceptions include exceptions thrown in a .NET Remoting application or a Web service application. Exceptions that cross application domains </span><a name="770"></a><a name="IDX-346"></a><span style="font-size:small;font-family:Calibri;">must be serialized to maintain the state. System exceptions are serializable. However, you need to make application exceptions serializable.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Follow these steps to serialize an application exception:</span></p>
<ol>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Adorn the application exception with the <em>serializable</em> attribute.</span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Implement a two-argument constructor with a <em>SerializationInfo</em> and <em>StreamingContext</em> parameter. Deserialize the exception with the <em>SerializationInfo</em> parameter, which is a state bag. Retrieve state information of the exception using the <em>Get</em> methods of the <em>SerializationInfo</em> object. The <em>StreamingContext</em> parameter provides additional data about the source or target of the serialization process. In addition, call the same constructor in the base class to allow the base class to deserialize its state.</span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Implement the <em>GetObjectData</em> method to serialize the exception. The method also has two parameters: <em>Serialization</em> and <em>StreamingContext</em>. Use the <em>Serialization.AddValue</em> to serialize the state of the exception. Invoke <em>GetObjectData</em> on the base class to allow it to serialize itself.</span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">For the exception to be available in the client assembly, share the assembly through a global assembly cache or an application configuration file. If the assembly is not shared, the assembly must be copied into the private directory of the client application.</span></div>
</li>
</ol>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em>CustomException</em> is an application exception that supports remoting. There is one property, <em>prop_Time</em>, which is serialized in <em>GetObjectData</em> and deserialized in the two-argument constructor:</span></span></p>
<pre class="brush: csharp;">using System;
using System.Reflection;
using System.Runtime.Serialization;

[assembly: AssemblyVersion(&quot;1.1.0.0&quot;)]
[assembly: AssemblyCultureAttribute(&quot;&quot;)]

namespace Examples.Exceptions
{

    [Serializable]
    public class CustomException : Exception
    {

        public CustomException() : base(&quot;custom exception&quot;, null)
        {
            prop_Time = DateTime.Now.ToLongDateString() + &quot; &quot; + DateTime.Now.ToShortTimeString();
        }

        protected CustomException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            prop_Time = info.GetString(&quot;Time&quot;);
        }

        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue(&quot;Time&quot;, prop_Time, typeof(string));
            base.GetObjectData(info, context);
        }

        protected string prop_Time = null;
        public string Time
        {
            get
            {
                return prop_Time;
            }
        }
    }
}</pre>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">In Microsoft Visual Studio, the assembly attributes, such as <em>AssemblyVersion</em>, are found in the <em>AssemblyInfo.cs</em> file.</span></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiman.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiman.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiman.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiman.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiman.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiman.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiman.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiman.wordpress.com/297/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiman.wordpress.com/297/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiman.wordpress.com/297/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=297&subd=shiman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shiman.wordpress.com/2008/11/06/remote-exceptions-in-c-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Shiman</media:title>
		</media:content>
	</item>
		<item>
		<title>Application Exceptions in C# .NET</title>
		<link>http://shiman.wordpress.com/2008/11/02/application-exceptions-in-c-net/</link>
		<comments>http://shiman.wordpress.com/2008/11/02/application-exceptions-in-c-net/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 13:47:01 +0000</pubDate>
		<dc:creator>shiman</dc:creator>
				<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[S/W Engineering]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://shiman.wordpress.com/?p=292</guid>
		<description><![CDATA[Application exceptions are custom exceptions and are thrown by the application, not by the CLR. Application exceptions are derived from System.ApplicationException or System.Exception. System.ApplicationException adds nothing to System.Exception. While System.SystemException is a marker for system exceptions, System.ApplicationException brands application exceptions. A custom exception derived from System.Exception accomplishes the same feat. When several custom exceptions are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=292&subd=shiman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Application exceptions are custom exceptions and are thrown by the application, not by the CLR. Application exceptions are derived from <em>System.ApplicationException</em> or <em>System.Exception</em>. <em>System.ApplicationException</em> adds nothing to <em>System.Exception</em>. While <em>System.SystemException</em> is a marker for system exceptions, <em>System.ApplicationException</em> brands application exceptions. A custom exception derived from <em>System.Exception</em> accomplishes the same feat. When several custom exceptions are planned, create a custom base exception class to categorize the exceptions. For convenience and maintainability, deploy application exceptions together in a separate assembly.</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Do not create an application exception for an existing exception. Research the available system exceptions to avoid replicating an existing exception.</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">These are the steps for creating an application exception:</span></span></span></p>
<ol>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Name the application exception. As a best practice, the class name should have the <em>Exception</em> suffix, as in <em>ApplicationException</em>.</span></span></span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Derive the application exception from <em>System.Exception</em>.</span></span></span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Define constructors that initialize the state of the application exception. This includes initializing members inherited from the base class.</span></span></span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Within the application exception, refine <em>System.Exception</em> as desired, such as by adding attributes that further delineate this specific exception.</span></span></span></div>
</li>
</ol>
<p class="MsoNormal" style="margin:0 0 10pt;"><a name="756"></a><a name="IDX-339"></a><span><span style="font-size:small;"><span style="font-family:Calibri;">To raise an application exception, use the <em>throw</em> statement. You can also throw system exceptions. Thrown exceptions are considered software exceptions. The CLR treats software exceptions as standard exceptions.</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">throw syntax:</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">throw <em>exceptioninstance</em><sup>1</sup>;</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">throw<sup>2</sup>;</span></span></span> </p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">The second syntax is specialized: It is available in the <em>catch</em> block, but nowhere else. This version of the <em>throw</em> statement rethrows as an exception caught in the <em>catch</em> block. However, the best policy is to add additional context to an exception before propagating the exception object. Propagating exceptions is reviewed later in this chapter.</span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Application exceptions are typically prompted by an exceptional event. What is an exceptional event? A strict definition does not exist. You define the basis of the event using whatever criteria are appropriate. Remember, raising an exception simply for transfer of control or a nonexceptional event is bad policy. In an application, the following could be considered exceptional events where throwing an application exception is warranted:</span></p>
<ul>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Constructor fails to initialize the state of an object.</span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">A property does not pass validation.</span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">Null parameters.</span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">An exceptional value is returned from a function.</span></div>
</li>
</ul>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em>ConstructorException</em> is an application exception. Throw this exception when a constructor fails. It refines the <em>System.Exception</em> base class with name of the type and time of exception. In addition, the <em>Message</em> property is assigned a congruous message. This is the code for the <em>ConstructorException</em> class:</span></span></p>
<pre class="brush: csharp;">using System;

namespace Examples.Exceptions
{
    public class ConstructorException : Exception
    {

        public ConstructorException(object origin) : this(origin, null)
        {
        }

        public ConstructorException(object origin, Exception innerException) : base(&quot;Exception in constructor&quot;, innerException)
        {
            prop_Typename = origin.GetType().Name;
            prop_Time = DateTime.Now.ToLongDateString() + &quot; &quot; + DateTime.Now.ToShortTimeString();
        }

        protected string prop_Typename = null;
        public string Typename
        {
            get
            {
                return prop_Typename;
            }
        }

        protected string prop_Time = null;
        public string Time
        {
            get
            {
                return prop_Time;
            }
        }
    }
}</pre>
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;font-family:Calibri;">This code uses the <em>ConstructorException</em> class:</span></p>
<pre class="brush: csharp;">using System;

namespace Examples.Exceptions
{
    public class Program
    {
        public static void Main()
        {
            try
            {
                ZClass obj = new ZClass();
            }
            catch (ConstructorException except)
            {
                Console.WriteLine(except.Message);
                Console.WriteLine(&quot;Typename: &quot; + except.Typename);
                Console.WriteLine(&quot;Occured: &quot; + except.Time);
            }
            Console.ReadKey();
        }
    }

    class ZClass
    {
        public ZClass()
        {
            // initialization fails
            throw new ConstructorException(this);
        }
    }
}</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiman.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiman.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiman.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiman.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiman.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiman.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiman.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiman.wordpress.com/292/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiman.wordpress.com/292/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiman.wordpress.com/292/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=292&subd=shiman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shiman.wordpress.com/2008/11/02/application-exceptions-in-c-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Shiman</media:title>
		</media:content>
	</item>
		<item>
		<title>C# .NET System.Exception Properties</title>
		<link>http://shiman.wordpress.com/2008/10/28/c-net-systemexception-properties/</link>
		<comments>http://shiman.wordpress.com/2008/10/28/c-net-systemexception-properties/#comments</comments>
		<pubDate>Tue, 28 Oct 2008 05:27:30 +0000</pubDate>
		<dc:creator>shiman</dc:creator>
				<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://shiman.wordpress.com/?p=276</guid>
		<description><![CDATA[System.Exception has a full complement of attributes providing information on the exception. The following table describes the properties of the Exception class.




Table: Exception Properties 




Property 


Description 


Type 


Read/Write 






Data 


Returns a dictionary collection that provides optional user-defined details of exception.


IDictionary 


R




HelpLink 


Link to a help file for the exception.


string 


R/W




HResult 


The HRESULT, which is a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=276&subd=shiman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal" style="text-align:left;margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>System.Exception</span></em><span> has a full complement of attributes providing information on the exception. The following table describes the properties of the <em>Exception</em> class.</span></span></span></p>
<table class="MsoNormalTable" style="text-align:center;border:windowtext 1pt solid;" border="1" cellpadding="0">
<thead>
<tr>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" colspan="4">
<p class="MsoNormal" style="text-align:center;margin:0 0 10pt;"><a name="753"></a><a name="ch09table02"></a><span><span style="font-size:small;"><span style="font-family:Calibri;">Table: <em>Exception</em> Properties </span></span></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span><span style="font-size:small;"><span style="font-family:Calibri;">Property </span></span></span></strong></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span><span style="font-size:small;"><span style="font-family:Calibri;">Description </span></span></span></strong></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span><span style="font-size:small;"><span style="font-family:Calibri;">Type </span></span></span></strong></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><strong><span><span style="font-size:small;"><span style="font-family:Calibri;">Read/Write </span></span></span></strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>Data</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Returns a dictionary collection that provides optional user-defined details of exception.</span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>IDictionary</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">R</span></span></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>HelpLink</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Link to a help file for the exception.</span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>string</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">R/W</span></span></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>HResult</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">The HRESULT, which is a 32-bit error code common to COM, assigned to the exception. This is a protected property.</span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>int</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">R/W</span></span></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>InnerException</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">When exceptions are propagated, the inner exception represents the previous exception.</span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>Exception</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">R</span></span></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>Message</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">User-friendly message describing the exception.</span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>string</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">R</span></span></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>Source</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Name of application or object where exception occurred.</span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>string</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">R/W</span></span></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>StackTrace</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">String representation of the call stack when the exception occurred.</span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>string</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">R</span></span></span></p>
</td>
</tr>
<tr>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>TargetSite</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Reference to the method where exception is raised.</span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span style="font-size:small;"><span style="font-family:Calibri;"><em><span>MethodBase</span></em><span> </span></span></span></p>
</td>
<td style="background-color:transparent;border:windowtext 1pt solid;padding:.75pt;" valign="top">
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">R</span></span></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal" style="text-align:left;margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">The <em>Message</em> and <em>InnerException</em> properties are settable in constructors of the <em>Exception</em> class.</span></span></span></p>
<p class="MsoNormal" style="text-align:left;margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">The following code uses some of the properties of the <em>Exception</em> class. In <em>Main</em>, <em>MethodA</em> is called, and an exception is raised. The exception is caught and handled in <em>Main</em>. In the <em>catch</em> block, the exception flag is set to false. Leveraging the <em>TargetSite</em> property, <em>MethodA</em> is then called again successfully. The <em>TargetSite</em> property returns a <em>MethodBase</em> type, which can be used to late bind and invoke a method.</span></span></span></p>
<pre class="brush: csharp;">using System;
using System.Reflection;

namespace Example.Exceptions
{
    public class Starter
    {
        public static bool bException = true;
        public static void Main()
        {
            try
            {
                MethodA();
            }
            catch (Exception except)
            {
                Console.WriteLine(except.Message);
                bException = false;
                except.TargetSite.Invoke(null, null);
                Console.ReadKey();
            }
        }

        public static void MethodA()
        {
            if (bException)
            {
                throw new ApplicationException(&quot;exception message&quot;);
            }
        }
    }
}</pre>
<p style="text-align:center;"><a name="pd_a_1051278"></a><div class="PDS_Poll" id="PDI_container1051278" style="display:inline-block;"></div><script type="text/javascript" language="javascript" charset="utf-8" src="http://static.polldaddy.com/p/1051278.js"></script>
		<noscript>
		<a href="http://answers.polldaddy.com/poll/1051278/">View This Poll</a><br/><span style="font-size:10px;"><a href="http://answers.polldaddy.com">opinion</a></span>
		</noscript></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiman.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiman.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiman.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiman.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiman.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiman.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiman.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiman.wordpress.com/276/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiman.wordpress.com/276/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiman.wordpress.com/276/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=276&subd=shiman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shiman.wordpress.com/2008/10/28/c-net-systemexception-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Shiman</media:title>
		</media:content>
	</item>
		<item>
		<title>C# .NET System.Exception Functions</title>
		<link>http://shiman.wordpress.com/2008/10/16/c-net-systemexception-functions/</link>
		<comments>http://shiman.wordpress.com/2008/10/16/c-net-systemexception-functions/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 18:05:13 +0000</pubDate>
		<dc:creator>shiman</dc:creator>
				<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://shiman.wordpress.com/?p=271</guid>
		<description><![CDATA[


System.Exception has four constructors:

public Exception1()
public Exception2(string message)
public Exception3(string message, Exception innerException)
protected Exception4(Serialization info, StreamingContext context)

Exception1 is the default constructor. Exception2 constructor sets the user-friendly message of the exception. Exception3 constructor also sets the inner exception, which is the originating exception. Exception4 deserializes an exception raised remotely.
The Exception class has several other helpful functions. The table [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=271&subd=shiman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal"><em></em></p>
<p><em></em></p>
<p><em></p>
<p class="MsoNormal"><em>System.Exception</em> has four constructors:</p>
<ul>
<li><em>public Exception</em><sup>1</sup><em>()</em></li>
<li><em>public Exception</em><sup>2</sup><em>(string message)</em></li>
<li><em>public Exception</em><sup>3</sup><em>(string message, Exception innerException)</em></li>
<li><em>protected Exception</em><sup>4</sup><em>(Serialization info, StreamingContext context)</em></li>
</ul>
<p class="MsoNormal"><em>Exception</em><sup>1</sup> is the default constructor. <em>Exception</em><sup>2</sup> constructor sets the user-friendly message of the exception. <em>Exception</em><sup>3</sup> constructor also sets the inner exception, which is the originating exception. <em>Exception</em><sup>4</sup> deserializes an exception raised remotely.</p>
<p class="MsoNormal">The <em>Exception</em> class has several other helpful functions. The table lists the important methods of the class.</p>
<table class="MsoTableGrid" border="1" cellspacing="0" cellpadding="0" width="631">
<tbody>
<tr>
<td colspan="2" width="631" valign="top">
<p class="MsoNormal" align="center"><span class="table-title"><strong><em><span>Table: Exception Methods</span></em></strong></span></p>
</td>
</tr>
<tr>
<td width="175" valign="top">
<p class="MsoNormal" align="center"><strong><span>Method   Name</span></strong></p>
</td>
<td width="456" valign="top">
<p class="MsoNormal" align="center"><strong><span>Result</span></strong></p>
</td>
</tr>
<tr>
<td width="175" valign="top">
<p class="MsoNormal"><em><span>GetBaseException</span></em><span> </span></p>
</td>
<td width="456" valign="top">
<p class="MsoNormal"><span>Returns the root exception   in a chain of exception objects</span></p>
</td>
</tr>
<tr>
<td width="175" valign="top">
<p class="MsoNormal"><em><span>GetObjectData</span></em><span> </span></p>
</td>
<td width="456" valign="top">
<p class="MsoNormal"><span>Serializes data of the <em>Exception</em> class</span></p>
</td>
</tr>
<tr>
<td width="175" valign="top">
<p class="MsoNormal"><em><span>GetType</span></em><span> </span></p>
</td>
<td width="456" valign="top">
<p class="MsoNormal"><span>Returns the type of the   exception</span></p>
</td>
</tr>
<tr>
<td width="175" valign="top">
<p class="MsoNormal"><em><span>ToString</span></em><span> </span></p>
</td>
<td width="456" valign="top">
<p class="MsoNormal"><span>Concatenates the name of   the exception object with the user-friendly message</span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><strong></strong></p>
<p><strong></strong></p>
<p><strong></p>
<p class="MsoNormal"><span style="font-weight:normal;">The following code calls </span><em><span style="font-weight:normal;">GetBaseException</span></em><span style="font-weight:normal;"> and outputs the error message of the initial exception. If the current exception is the first exception in a chain of exceptions, </span><em><span style="font-weight:normal;">GetBaseException</span></em><span style="font-weight:normal;"> returns null. Alternatively, you can walk </span><em><span style="font-weight:normal;">InnerException</span></em><span style="font-weight:normal;"> properties back to the first exception.</span></p>
<p></strong></em></p>
<pre class="brush: csharp;">using System;

namespace Example.Exceptions
{
    public class Program
    {
        public static void Main()
        {
            try
            {
                MethodA();
            }
            catch (Exception except)
            {
                Exception original = except.GetBaseException();
                Console.WriteLine(original.Message);
            }

            Console.ReadKey();
        }

        public static void MethodA()
        {
            try
            {
                MethodB();
            }
            catch (Exception except)
            {
                throw new ApplicationException(&quot;Inner Exception&quot;, except);
            }
        }

        public static void MethodB()
        {
            throw new ApplicationException(&quot;Innermost Exception&quot;);
        }
    }
}</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiman.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiman.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiman.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiman.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiman.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiman.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiman.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiman.wordpress.com/271/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiman.wordpress.com/271/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiman.wordpress.com/271/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=271&subd=shiman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shiman.wordpress.com/2008/10/16/c-net-systemexception-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Shiman</media:title>
		</media:content>
	</item>
		<item>
		<title>C# .NET Exceptions : Propagating Exceptions</title>
		<link>http://shiman.wordpress.com/2008/10/07/c-net-exceptions-propagating-exceptions/</link>
		<comments>http://shiman.wordpress.com/2008/10/07/c-net-exceptions-propagating-exceptions/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 09:15:22 +0000</pubDate>
		<dc:creator>shiman</dc:creator>
				<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://shiman.wordpress.com/?p=269</guid>
		<description><![CDATA[Exceptions are not always handled locally where the exception is caught. It is sometimes beneficial to catch an exception and then propagate the exception. Propagating an exception is catching and then rethrowing the exception. Rethrowing an exception continues the search along the call stack to find an appropriate handler. Here are some reasons to propagate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=269&subd=shiman&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Exceptions are not always handled locally where the exception is caught. It is sometimes beneficial to catch an exception and then propagate the exception. <em>Propagating</em> an exception is catching and then rethrowing the exception. Rethrowing an exception continues the search along the call stack to find an appropriate handler. Here are some reasons to propagate an exception:</span></span></span></p>
<ul>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">There is a centralized handler for the exception. There are several reasons for implementing centralized handlers, including code reuse. Instead of handling an exception in various locations in an application, concentrate code for certain exceptions in a centralized handler. Wherever the exception is raised, the proper response is to record the exception and then delegate to the centralized handler. A central handler can be used to handle all exceptions in a single place.</span></span></span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><a name="738"></a><a name="IDX-331"></a><span><span style="font-size:small;"><span style="font-family:Calibri;">Resources required to handle the exception are not available locally. For example, an exception is raised because of an invalid database connection. However, the correct connection string is read from a file not available where the exception occurs. The solution is to propagate the exception to a handler that has access to the file resource.</span></span></span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Propagate unwanted exceptions caught in the umbrella of the exception filter. This would be useful for catching all <em>DataException</em> types with the exception of the <em>DuplicateNameException</em>. One solution would be to write 12 individual catches—one for each of the data exceptions except for the <em>DuplicateNameException</em> exception. A better solution is to catch the <em>DataException</em> type and propagate the <em>DuplicateNameException</em> when necessary. This is one <em>catch</em> statement versus 12 <em>catch</em> statements and eliminates redundant code.</span></span></span></div>
</li>
<li>
<div class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Catch an exception to gather information or to report on an exception, and then propagate the exception.</span></span></span></div>
</li>
</ul>
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">To propagate an exception, rethrow the same exception or another exception in the <em>catch</em> block. An empty <em>throw</em> statement propagates the caught exception. Alternatively, throw a different exception.</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">Exceptions might propagate through several layers of an application. Ultimately, the exception could percolate to the user interface level. As an exception percolates, the exception becomes less specific. Exceptions from the lower echelon of an application contain detailed information appropriate to the application developer, but probably not relevant to the user. Internal exceptions might contain security and other sensitive information not appropriate for a benign (or malicious) user. Record the facts of the internal exception if logging is preferable. Exceptions that reach the user should present user-relevant information: a user-friendly message, steps to resolve the exception, or even a customer support link.</span></span></span></p>
<p class="MsoNormal" style="margin:0 0 10pt;"><span><span style="font-size:small;"><span style="font-family:Calibri;">When an original exception is rethrown, you can preserve the <em>that</em> exception in the <em>InnerException</em> attribute. Successive <em>InnerException</em> attributes form a chain of exceptions from the current exception to the original exception. The <em>InnerException</em> can be initialized in the constructor of the new exception. Here is sample code that propagates an exception and sets the inner exception:</span></span></span></p>
<pre class="brush: csharp;">using System;

namespace Examples.Exceptions
{
    public class Program
    {
        public static void Main()
        {
            try
            {
                MethodA();
            }
            catch (Exception except)
            {
                Console.WriteLine(except.Message);
            }
        }

        public static void MethodA()
        {
            try
            {
                MethodB();
            }
            catch (DivideByZeroException inner)
            {

                // record divide by zero exception in event log.

                // except is inner exception
                throw new Exception(&quot;Math exception&quot;, inner);
            }
        }

        public static void MethodB()
        {
            int var1 = 5, var2 = 0;
            var1 /= var2;
        }
    }
}</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiman.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiman.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiman.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiman.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiman.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiman.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiman.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiman.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiman.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiman.wordpress.com/269/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiman.wordpress.com&blog=3675704&post=269&subd=shiman&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shiman.wordpress.com/2008/10/07/c-net-exceptions-propagating-exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">Shiman</media:title>
		</media:content>
	</item>
	</channel>
</rss>