473,396 Members | 1,858 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,396 software developers and data experts.

Getting the name of the calling method

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

Jul 17 '05 #1
1 7986
"Gilles A." <Gi********************@bpr-cso.com> wrote in message news:<5W*****************@charlie.risq.qc.ca>...
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

Hi,

The best thing you can do is avoid that functionality, it's just not
meant to be in Java.

If you, however, really really need it, you can use a dirty hack like
throwing an exception where you need to get the caller name, catching
it immediately, and then use Throwable.getStackTrace() to get your
callers from your catched exception.

Bear in mind that using exceptions to handle non-exceptional
conditions is a bad practice, and shall be discouraged!

Regards,

Andrey Andreev

Software developer
Jul 17 '05 #2

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

Similar topics

2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
10
by: Peter Afonin | last post by:
Hello, I have a simple client-side form that is checking the domain availability on the domain registrar's server: <FORM action="https://www.webnames.ru/scripts/RegTimeSRS.pl" method="post">...
0
by: ruju00 | last post by:
I am getting an error in Login() method of the following class FtpConnection public class FtpConnection { public class FtpException : Exception { public FtpException(string message) :...
1
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- ...
17
by: Mitko Haralanov | last post by:
I need to be able to get the name of the currently executed method within that method. I know that the method object does have the __name__ attribute but I know know how to access it from withing...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
14
AnuSumesh
by: AnuSumesh | last post by:
Hi all, I am writing one application using c# in which firstly I m getting impersonating the user and then i want to retrieve mapped Drives. But issue is when I am calling method in following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.