
Getting the function's name during runtime while running in the scope of the function
I'm going to go ahead and reply to my own post. I figured out what is needed to do what I suggest below (in my previous post). This post is for the benefit of those who want to know how to do this...
Imports System.Reflection
'Code...
Private Function DoAlotOfWork()
Try
'Lotsa Code!
Catch Ex as Exception
Throw New CustomException(MethodBase.GetCurrentMethod().Name(), Ex)
End Try
End Function
'Code....
MethodBase.GetCurrentMethod().Name().ToString() will return "DoAlotOfWork"
The true reasoning behind why I am doing this is to override the TargetSite attribute of the Exception class. You could find many other reasons to use it!
Sweet, huh?!?
Ricky
Quote:
> If the subject sounds confusing, then let me try to explain the end goal. My
> app has its own custom exception class, and within it I would like to send
> it the name of the function in which the exception occured. I could easily
> write code like this....
> Private Function DoAlotOfWork()
> Try
> 'Lotsa Code!
> Catch Ex as Exception
> Throw New CustomException("DoAlotOfWork", Ex)
> End Try
> Instead, I am looking to *not* hardcode the name of the function. I was
> hoping the reflection namespace would give me something but I have not had
> great results when searching the help files in VS.net.
> Can someone point me in the right direction?
> Ricky