Thursday, August 20, 2009

Exception handling in Enterpirse Library 4.1

After goggling lot very patiently,I find something all irrelevant to my task.
Finally i corrected by watching carefully on my system thrown exceptions.

Add this below line between ConfigSection of tag.

section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling" /

Paste this line somewhere but between configuration tag
exceptionHandling
exceptionPolicies
add name="Global Policy"
exceptionTypes
add name="Exception"
type="System.Exception,
mscorlib, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089"
postHandlingAction="None"

/add
/exceptionTypes
/add
/exceptionPolicies
/exceptionHandling

My source code for catching the exception is

try
{
int a = 0;
int b = 1;
int result = b / a;
Response.Write(result.ToString());

}
catch (System.Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "Global Policy");
Response.Write(rethrow.ToString());

}

Output is "False".So I am strongly believe exceptions were caught by enterprise library : )-