Getting the function's name during runtime while running in the scope of the function 
Author Message
 Getting the function's name during runtime while running in the scope of the function

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



Tue, 24 Aug 2004 05:06:44 GMT  
 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



Tue, 24 Aug 2004 13:11:47 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Retrieve name of Function, Sub, Class, Property etc from within that item during runtime

2. Getting the name of the function currently running

3. Determining a function's name at runtime

4. Trim() function in query can't be run in Access Runtime Environment

5. PROBLEM: getting a new control in front of others during runtime

6. Getting user name during NT logon

7. Getting the user's logon name and computer name

8. Executing a function during runtime

9. Executing a function() during runtime

10. write and run code during runtime

11. Can't modify code during runtime anymore?

12. variable names during run time ?

 

 
Powered by phpBB® Forum Software