By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,154 Members | 1,405 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,154 IT Pros & Developers. It's quick & easy.

How to obtain function's name?

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.