Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Custom Exception Framework: Using Enterprise Library Exception Handling Block

, 30 Oct 2008
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)

Share

About the Author

santosh poojari
Technical Lead
India India
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!
www.santoshpoojari.blogspot.com

| Advertise | Privacy | Mobile
Web04 | 2.8.140902.1 | Last Updated 30 Oct 2008
Article Copyright 2008 by santosh poojari
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid