Read exception policies

Topics: Exception Handling Application Block, General discussion
Jun 16, 2009 at 9:52 PM

How can I enumerate the exception policies in my config and each one's exception types that are being handled?  Is it possible to get their handlers too?

Jun 17, 2009 at 1:52 AM

Yes, it sure is possible.  Here's a sample code reading exception policies from an app.config/web.config.

            IConfigurationSource configSource = new SystemConfigurationSource();
            ExceptionHandlingSettings ehSettings = (ExceptionHandlingSettings)configSource.GetSection("exceptionHandling");
            foreach (var policy in ehSettings.ExceptionPolicies)
            {
                Console.WriteLine(policy.Name);
                foreach (var exceptionTye in policy.ExceptionTypes)
                {
                    Console.WriteLine(exceptionTye.Name);
                    foreach (var handler in exceptionTye.ExceptionHandlers)
                    {
                        Console.WriteLine(handler.TypeName);
                    }
                }
            }

Hope this helps.

Sarah Urmeneta
Global Technology & Solutions
Avande, Inc.
entlib.support@avanade.com