Click here to Skip to main content
15,883,818 members
Articles / Web Development / ASP.NET

Custom Exception Framework: Using Enterprise Library Exception Handling Block

Rate me:
Please Sign up or sign in to vote.
3.95/5 (16 votes)
30 Oct 2008CPOL3 min read 69.4K   1.1K   42  
This article demonstrates a working model of a custom Exception block using Enterprise Library Exception Handling Block which is built around MVP architecture.
<?xml version="1.0"?>
<!-- 
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
    \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
<configuration>
	<configSections>
		<section name="exceptionHandling" 
		   type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, 
		   Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.75.0, Culture=neutral, 
		   PublicKeyToken=b69d2d350639533d"/>
	</configSections>
	<exceptionHandling>
		<exceptionPolicies>
			<add name="Global Policy">
				<exceptionTypes>
					<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral,
						PublicKeyToken=b77a5c561934e089" 
						postHandlingAction="None" 
						name="Exception">
						<exceptionHandlers>
							<add type="Project.Practice.MVP.ExceptionHandling.ApplicationExceptionHandler, 
								Project.Practice.MVP.ExceptionHandling, Version=1.0.0.0, Culture=neutral, 
								PublicKeyToken=null" 
								name="Custom Handler"/>
						</exceptionHandlers>
					</add>
				</exceptionTypes>
			</add>
			<add name="Propogate Policy">
				<exceptionTypes>
					<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, 
						PublicKeyToken=b77a5c561934e089" 
						postHandlingAction="NotifyRethrow" 
						name="Exception">
					</add>
				</exceptionTypes>
			</add>
			<add name="Presenter Layer Policy">
				<exceptionTypes>
					<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, 
						PublicKeyToken=b77a5c561934e089" 
						postHandlingAction="ThrowNewException" 
						name="Exception">
						<exceptionHandlers>
							<add exceptionMessage="Presenter Layer Exception" 
							wrapExceptionType="Project.Practice.MVP.ExceptionHandling.CustomException.PresenterLayerException, 
							Project.Practice.MVP.ExceptionHandling, Version=1.0.0.0, Culture=neutral, 
							PublicKeyToken=null" 
							type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler,
							Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.75.0, Culture=neutral,
							PublicKeyToken=b69d2d350639533d" 
							name="Wrap Handler"/>
						</exceptionHandlers>
					</add>
				</exceptionTypes>
			</add>
			<add name="DataAccess Layer Policy">
				<exceptionTypes>
					<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
							postHandlingAction="ThrowNewException" 
						    name="Exception">
						<exceptionHandlers>
							<add exceptionMessage="Data Access Layer Exception" 
							wrapExceptionType="Project.Practice.MVP.ExceptionHandling.CustomException.DataAccesLayerException, 
							Project.Practice.MVP.ExceptionHandling, Version=1.0.0.0, Culture=neutral, 
							PublicKeyToken=null" 
							type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler,
							Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.75.0, Culture=neutral, 						
							PublicKeyToken=b69d2d350639533d" 
							name="Wrap Handler"/>
						</exceptionHandlers>
					</add>
				</exceptionTypes>
			</add>
			<add name="View Layer Policy">
				<exceptionTypes>
					<add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, 
						PublicKeyToken=b77a5c561934e089" 
						postHandlingAction="ThrowNewException" 
						name="Exception">
						<exceptionHandlers>
							<add exceptionMessage="UI Layer Exception" 
							wrapExceptionType="Project.Practice.MVP.ExceptionHandling.CustomException.ViewLayerException,
							Project.Practice.MVP.ExceptionHandling, Version=1.0.0.0, Culture=neutral, 
							PublicKeyToken=null" 
							type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WrapHandler, 
							Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.75.0, Culture=neutral, 
							PublicKeyToken=b69d2d350639533d" name="Wrap Handler"/>
						</exceptionHandlers>
					</add>
				</exceptionTypes>
			</add>		
		</exceptionPolicies>
	</exceptionHandling>
	<appSettings/>
	<connectionStrings/>
	<system.web>
		<!-- 
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        -->
		<compilation debug="true">
			<assemblies>
				<add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
				<add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
		<!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
		<authentication mode="Windows"/>
		<!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
	</system.web>
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
Australia Australia
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!
www.santoshpoojari.blogspot.com

Comments and Discussions