473,549 Members | 2,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7999
"Gilles A." <Gi************ ********@bpr-cso.com> wrote in message news:<5W******* **********@char lie.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.getSt ackTrace() 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
6899
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 a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This...
6
22498
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 instance (in this case 'myDog'). Of course it would be better if I could somehow know from within write() that the name of the object instance was...
10
1921
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"> <input type="hidden" name="thisPage" value="pispCheckDomain"> <input type="hidden" name="username" value="test"> <input type="hidden"...
0
3699
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) : base(message){} public FtpException(string message, Exception innerException) : base(message,innerException){}
1
9472
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:- onclick="retrieveURL('/application/home_page.do?processAction=ItinerarySearch','AfoHomeForm')" after clicking on button i am getting following error:- object...
17
21968
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 the method. Something like this: class A: ..... def a_method (self, this, that):
7
2667
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 name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling...
1
4909
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 order, Input field and a submit button. The Category name is being fetched from the oracle db along with the corresponding Category order. In...
14
5374
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 sequence: 1. create object of class 2. call mappeddrives() method 3. call impersonate method then its working fine.
0
7446
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6040
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5087
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.