obtain function name at runtime

  • Thread starter Thread starter Sylvain Provencher
  • Start date Start date
S

Sylvain Provencher

How can I obtain function name at runtime ? example : to display the
name of the function that cause an error
 
How can I obtain function name at runtime ? example : to display the
name of the function that cause an error

Check out the CallStack member of Exception.
 
if you are doing this in response to an exception, indeed look at the
callstack member of the Exception class.

if you are doing this as a result of receiving some unexpected return value
from the function, you can obtain function names at runtime. but this is
an expensive operation and you will have to pay for it :) it is often
better to consider how you called the function in the first place because
you might know the function name at compile time - in which case you don't
have to pay the cost of computing its name.

otherwise, there is a rich API in the .NET FCL called System.Reflection
which allows you to look at method names in Types. specifically, you could
check out Type.GetMethods

let me know if you need more hlep.

jeff.

--

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
 
Back
Top