How can I find out the name of the routine that is currently running?

M

Mr.Magic

I have some error handling routines that I'd like to pass to them as a
parameter what the name of the routine was that called it. How can I find
that out?

TIA - Jeff
 
M

Mr.Magic

OK. I found MethodBase.GetCurrentMethod().Name

But that only returns the name of the routine. How about the entire
namespace for it? Or at least the class name for it?

TIA - Jeff
 
J

Jeff Johnson

OK. I found MethodBase.GetCurrentMethod().Name

But that only returns the name of the routine. How about the entire
namespace for it? Or at least the class name for it?

this.GetType().FullName ?
 
B

Ben Voigt [C++ MVP]

MethodBase running = MethodBase.GetCurrentMethod();
running.Name
running.DeclaringType
etc, etc.

Mr.Magic said:
OK. I found MethodBase.GetCurrentMethod().Name

But that only returns the name of the routine. How about the entire
namespace for it? Or at least the class name for it?

TIA - Jeff





__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
B

Ben Voigt [C++ MVP]

Jeff Johnson said:
this.GetType().FullName ?

class X
{
virtual void whoami() { Trace.WriteLine(this.GetType().FullName); }
}

class Y : X
{
virtual void whoami() { base.whoami(); }
}

new Y().whoami();
__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4512 (20091015) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
P

Patrice

As a side note the whole stack trace is already part of the exception so if
this is some exception handling code you should have already this
available...

Depends what exactly you want to do...
 
M

Mr.Magic

I actually need it in places where I'm not in the exception routine yet.
Just status information.

But thanks anyway.
 
A

Appr3nt1c3

I actually need it in places where I'm not in the exception routine yet.
Just status information.

But thanks anyway.

"Patrice" <http://scribe-en.blogspot.com/> wrote in message

Try this:

try
{
throw new Exception("TEST");
}
catch (Exception ex)
{
Class1.Err(ex);
}

where class1 handles your stack trace calls.
 
B

Ben Voigt [C++ MVP]

Patrice said:
Great, was just to make sure as you talked about an "error handling"
routine.

error != exception

And often the stack trace of the exception is useless without some context
(what happened just before, etc) which requires logging in the absence of
exceptions.
 
P

Patrice

error != exception

You just don't even have errors in .NET hence I thought the OP meant an
exception. It looks to be what I would just call a trace...
 
B

Ben Voigt [C++ MVP]

Patrice said:
You just don't even have errors in .NET hence I thought the OP meant an

I guess these aren't part of .NET (just to name a few)?

http://msdn.microsoft.com/en-us/lib...nteropservices.marshal.getlastwin32error.aspx
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.errorreceived.aspx
http://msdn.microsoft.com/en-us/library/system.net.sockets.socketerror.aspx
exception. It looks to be what I would just call a trace...

--
Patrice




__________ Information from ESET NOD32 Antivirus, version of virus
signature database 4522 (20091019) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4522 (20091019) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com
 
P

Patrice

Granted could be perhaps that. From a code point of view this is just a
state that is read back. Was just not my first thought when reading about an
error handling routine. Sorry about that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top