Modify ExceptionPolicy class

Topics: Building and extending application blocks, Exception Handling Application Block
Jun 2, 2009 at 7:21 AM

Hi,

I want to modify ExceptionPolicy class so that i can add more parameters to HandleException method.Pla suggest me way to do that.

Thanks,

 

Jun 2, 2009 at 7:34 AM

Hi,

I'm just curious what would be your goal for adding more parameters?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

 

Jun 2, 2009 at 7:56 AM

Hi,

I want to create common functionality to handle exceptions.For that i want collect some custom additional information like user id etc.

i know it can be done by  ex.Data.Add("Custom Details", "Details"). But by doing this way i can't restrict developers to add that additional details. Thats why i want to modify HandleException so that whenever developers use this method they have to pass additional parameters.

Thanks,

 

Jun 2, 2009 at 9:37 AM

Is this for logging purpose only? or you have another thing in mind?

Jun 2, 2009 at 10:03 AM

I also want to replace and wrap exception but that i will do. Logging is the part where i am feeling some problem beacuse i need some extra information to logged that why i want to modify  HandleException

Thanks,

 

Jun 2, 2009 at 11:25 AM

You may add another parameter, say IDictionary<string, object> type, then implement your code. For the scenario of Logging, you can just add the contents of the IDictionary to the exception.Data.

Something like this:

        public static bool HandleException(Exception exceptionToHandle, string policyName, IDictionary<string, object> additionalInformation)

        {

            if (exceptionToHandle == null) throw new ArgumentNullException("exceptionToHandle");

            if (string.IsNullOrEmpty(policyName)) throw new ArgumentException(Resources.ExceptionStringNullOrEmpty);

 

            if (additionalInformation != null && additionalInformation.Count > 0)

            {

                foreach(KeyValuePair<string, object> info in additionalInformation)

                {

                    exceptionToHandle.Data.Add(info.Key, info.Value);

                }

            }

            return HandleException(exceptionToHandle, policyName, defaultFactory);

        }

 Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com