EHAB and Unit Tests without full configuration defined

Topics: Exception Handling Application Block
May 19, 2009 at 10:38 PM

We have a large project with multiple layers.  The business layer has a class with a method something like:



            catch(Exception ex)
                // Quick Start is configured so that the Propagate Policy will
                // log the exception and then recommend a rethrow.
                bool rethrow = ExceptionPolicy.HandleException(ex, "Propagate Policy");

                if (rethrow)



My question is this... is there any way to determine if the ExceptionHandling block has been configured?  I ask because, if this method is called from a unit test that is testing the DAL or business layer, it likely wouldn't have access to our web.config file.

If the config file doesn't exist, then when an exception is thrown, our exception is replaced with an ExceptionHandlingException thrown by the block because it is not configured.

What is the best pattern to work around this, without having to duplicate the config file?


May 20, 2009 at 3:30 AM

You can use this..

SystemConfigurationSource s = new SystemConfigurationSource();
ConfigurationSection exceptionHandlingSection = s.GetSection("exceptionHandling");

If exceptionHandlingSection is null, then either the configuration file is not present or there was no exception handling section in the config file.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.