Custom properties in a Custom Handler

Topics: Exception Handling Application Block
Nov 5, 2009 at 5:00 PM
Edited Nov 5, 2009 at 5:03 PM


I have an Exception Policy to handle the exceptions from the type System.Exception. I have a Custom Handler, and I want to pass an attribute to my Custom Handler.

I added it in General, Attributes, Collection and set a Key and a Value for my attribute.

Does anybody know how I can retrieve my attribute information in my Custom Handler?



Paco Cruzado

Nov 6, 2009 at 2:06 AM

You can access it in your custom handler thru the Attributes property.  The contents will be available except in the constructor. 

string myValue = this.Attributes["myKey"];


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Nov 6, 2009 at 7:40 AM

That's what I tried the first time, but I wasn't able to reach the attributes, maybe I have a wrong structure.

I'm working in VB and my Custom Handler implements the Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler interface.

I can't access to the attributes from the object Me, and I don't know if I'm missing something.

I've traid with this:

     Public Class ManejadorExcepcionesPresentacion
        Implements Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler

        Public Function HandleException(ByVal exception As System.Exception, ByVal handlingInstanceId As System.Guid) As System.Exception _
            Implements Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.IExceptionHandler.HandleException
                Dim messageAs String = Me.attributes("GlobalMessage")
            Catch ex As ThreadAbortException
            End Try

            Return exception

        End Function

        Public Sub New(ByVal ignore As NameValueCollection)
        End Sub

        Public Sub New()
        End Sub
    End Class



Nov 6, 2009 at 7:49 AM

When you said you can't access the attributes, are you saying there's no Attributes property available in the Me object or the contents you entered in the config are not present in the Attributes property?


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Nov 6, 2009 at 7:52 AM

The first one, there is no Attributes property in the Me object.


Nov 6, 2009 at 8:03 AM

My bad, I was so used to a custom trace listener.  To get the values of the Attributes property collection, create a constructor that takes a NameValueCollection parameter.   That parameter will contain the items you added in the Attributes property.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.