[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 860
  • Last Modified:

Return method name on exception

Hi all

I have Try Catches all through my code, but if and when an exception occurs, I'd like to return the class and method name that pulled the exception ...

Example:

        Try
            ...some code
        Catch ex As Exception
            Msg.Text = "This error occured in this class: " & currentClassName & " and this method: " & currentMethodName & ex.Message
        End Try

Anyone got any ideas of how to make it happen in an automated fashion? ie. I don't want to MANUALLY go through each function and assign a variable to remember the name of the class and function.

Cheers,
Mark
0
msiedle
Asked:
msiedle
1 Solution
 
ctm5Commented:
This is pretty easy to do. The Exception can tell you the name of the method:

ex.TargetSite.GetCurrentMethod.Name

To get the name of the class, the only way I have found is to look at

ex.StackTrace

and parse it to get what you want.

ctm5
0
 
msiedleAuthor Commented:
Beautiful! Thanks very much :-)

M
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now