Getting the name of the calling method

G

Gilles A.

Hi all,

Does anyone know how to get the class.method name of the calling method?

Example
public class A
{
public void m()
{
new B().method();
}
}
public class B
{
public void method()
{
// Here I need to know who called me.
// I need to print "A.m()" in a stream.
}
}

I tought JDK 1.4 was offering that functionnality but I can't find it
anywhere.

Does anyone have an idea?

Thanks in advance,

Gilles
 
F

Fred L. Kleinschmidt

Gilles A. said:
Hi all,

Does anyone know how to get the class.method name of the calling method?

Example
public class A
{
public void m()
{
new B().method();
}
}
public class B
{
public void method()
{
// Here I need to know who called me.
// I need to print "A.m()" in a stream.
}
}

I tought JDK 1.4 was offering that functionnality but I can't find it
anywhere.

Does anyone have an idea?

Thanks in advance,

Gilles

See the printStackTrace method of Throwable
 
T

Tom McGlynn

Gilles A. said:
Hi all,

Does anyone know how to get the class.method name of the calling method?

Example
public class A
{
public void m()
{
new B().method();
}
}
public class B
{
public void method()
{
// Here I need to know who called me.
// I need to print "A.m()" in a stream.
}
}

I tought JDK 1.4 was offering that functionnality but I can't find it
anywhere.

Does anyone have an idea?

Thanks in advance,

Gilles

A couple of other posters pointed out the Throwable.printStackTrack method,
but for your purposes Throwable.getStackTrace is probably what you want.
You'd probably have run across it looking at printStackTrace, but just
in case...
Regards,
Tom McGlynn
 

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

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top