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

  • Thread starter Thread starter Mr.Magic
  • Start date Start date
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
 
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
 
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 ?
 
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
 
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
 
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...
 
I actually need it in places where I'm not in the exception routine yet.
Just status information.

But thanks anyway.
 
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.
 
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.
 
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...
 
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
 
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.
 
Back
Top