Return method name on exception

Posted on 2006-04-26
Last Modified: 2008-02-26
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 ...


            ...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.

Question by:msiedle
    LVL 6

    Accepted Solution

    This is pretty easy to do. The Exception can tell you the name of the method:


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


    and parse it to get what you want.

    LVL 2

    Author Comment

    Beautiful! Thanks very much :-)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now