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
LVL 2
msiedleAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
msiedleAuthor Commented:
Beautiful! Thanks very much :-)

M
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.