473,325 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to obtain function's name?

How to obtain a function name during the execution code?

For example:

public void Acme()
{
try
{
some code goes here
}
catch(Exception ex)
{
MessageBox.Show("Oops, an error occured at " + <here goes
'Acme'>, "Title",...);
}
}
Thanks in advance!

May 16 '06 #1
4 4651
Use the StackFrame class in the System.Diagnostics namespace, like so:

// Get the current stack frame.
StackFrame stackFrame = new StackFrame();

// Write the method name:
Console.WriteLine(stackFrame.GetMethod().Name);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<vc*******@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
How to obtain a function name during the execution code?

For example:

public void Acme()
{
try
{
some code goes here
}
catch(Exception ex)
{
MessageBox.Show("Oops, an error occured at " + <here goes
'Acme'>, "Title",...);
}
}
Thanks in advance!

May 16 '06 #2
If you go back and examine the Exception object that you caught, you will see
it has a number of properties. The StackTrace will give you a lot of
information.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"vc*******@gmail.com" wrote:
How to obtain a function name during the execution code?

For example:

public void Acme()
{
try
{
some code goes here
}
catch(Exception ex)
{
MessageBox.Show("Oops, an error occured at " + <here goes
'Acme'>, "Title",...);
}
}
Thanks in advance!

May 16 '06 #3
Excuse me, I forgote to mention that I'm developing for CompactCE.
I can't see StackFrame in Compact Framework.

Thanks

May 16 '06 #4
May be

System.Reflection.MethodBase.GetCurrentMethod.Name ()

???

SA

<vc*******@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
Excuse me, I forgote to mention that I'm developing for CompactCE.
I can't see StackFrame in Compact Framework.

Thanks

May 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sylvain Provencher | last post by:
How can I obtain function name at runtime ? example : to display the name of the function that cause an error
4
by: Gnanaprakash Rathinam | last post by:
Hi Expert, Is there a way to obtain assembly name in an unmanaged call? During Interop call between managed to unmanaged, I would like to know in unmanaged code about the caller of assembly file...
11
by: babuyama | last post by:
Hi, Is there a way to obtain library name at compile/preprocessor time? Assuming that the compilation unit, myfile.c is part of mylib.a, from myfile.c code at compile/preprocessor time, I would...
1
by: Alex | last post by:
I have two functions A & B. The function A calls function B. How can I programatically determine within body of function B the name of function (in our case it is A) that function B was called by?...
2
by: Yarik | last post by:
Hello, I am not sure the subject of my post adequately describes the problem I am trying to solve, so I think a specific example would be helpful. Let's say there are XML descriptions of...
1
by: Yaro | last post by:
Hi How obtain server (machine name) with db2 8.1.5 ? I need get this name in select statement: select (something) from sysibm.sysdummy1 Would be nice also obtain fixpack level.
8
by: Paul Bromley | last post by:
Thanks for your tolerance on this list. I asked the question regarding Commercial Copy Protection along with Unique PC Idnetifier and obtaining the active IP address. This was all to identify and...
6
by: Maguila007 | last post by:
Hi Is there any way to obtain the name of the function, inside the function which was called. Ex: function something() { alert( "The name of the function you invoke is " ......should
3
by: Martin | last post by:
Hi. I need to identify the type of the exception in the universal handler (catch (...)) for debugging purposes. Point is that I write a testing console application, which must call some...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.