Function/Sub name RRS feed

  • Question

  • Is it possible to get the function or sub routine name inside of a function sub routine?  Would like to include as part of error handling and logging.


    Mark Brennan
    Wednesday, August 17, 2005 6:56 PM


  • You can use Environment.StackTrace, but you have to parse the string yourself to get just the method name.

    This probably uses reflection to read the method names from meta-data, so it could be an expensive call - be aware of that when just logging data.

    For error handling, this isn't neccessary. The exception object already has a StackTrace property, which is also included in the text returned by Exception.ToString().
    Wednesday, August 17, 2005 8:27 PM