471,075 Members | 799 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

obtain function name at runtime

How can I obtain function name at runtime ? example : to display the
name of the function that cause an error
Jul 21 '05 #1
3 1381
> 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.

--
-Jimmy
Jul 21 '05 #2
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.

Jul 21 '05 #3

If you just want to use it for a trace, you can use __FUNCTION__

Mihai
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Frank DeLuccia | last post: by
6 posts views Thread by anonymous | last post: by
3 posts views Thread by Sylvain Provencher | last post: by
6 posts views Thread by Maguila007 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.