SharpCrafters Support Forum

        


Accessing class objects from OnException Expand / Collapse
Author
Message
Posted 2/22/2012 2:39:35 PM


Community Member
I'm playing around with Day 1

http://www.sharpcrafters.com/blog/post/Day-1-e28093-OnExceptionAspect.aspx

Is there a way to be able to access class objects from the class throwing the error in OnException?

While the stacktrace is handy, I really need to be able to log other pieces of information to help track the error.  

Conisder:


Class Foo
   Public User As String
   Public PhoneNumber As String

   Public Function Bar() As Boolean
       Dim c As Collection 'intentionally not set to an object to cause an error below
       c.Add(PhoneNumber)
       Return True
   End Function
End Class


While using PostSharp would give me the stacktrace in OnException, I really need access to User and PhoneNumber to log those into the my message.

Any suggestions?
Post #8374
Posted 2/22/2012 2:55:35 PM


Gael Fraiteur

SharpCrafters
Sure, you can use (in C# syntax):


string phone = ((Foo) args.Instance).PhoneNumber
Post #8375
Posted 2/22/2012 4:34:55 PM


Community Member
Amazing!
Post #8376
« Prev Topic | Next Topic »


All times are GMT +1:00, Time now is 3:42am