Can It Be Done?

  • Thread starter Thread starter Mchuck
  • Start date Start date
M

Mchuck

This is an interesting question I have been looking for on
the net with not much luck. It has to do with returning
the function name you're currently in during code
execution. Say for example, I have a function called
FindTheAverage, and during the use of it, an error occurs
that jumps to the error handler of the function. What I
want is the ability to return the name of the function
here without having to hard code it as a string variable
with the name "FindTheAverage" in it. Is this even
remotely possible? Does anyone have any thoughts on this?
 
Mchuck,
Have you looked at the System.Exception.StackTrace?

try
{
MethodThatThrowsException();
}
catch (System.Exception e)
{
Console.WriteLine(e.StackTrace);
}
 
Back
Top