The Artima Developer Community
Sponsored Link

Java Answers Forum
Who Called Me?

3 replies on 1 page. Most recent reply: Mar 22, 2004 8:50 AM by Balasubramanian Natarajan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Balasubramanian Natarajan

Posts: 2
Nickname: pranavbala
Registered: Mar, 2004

Who Called Me? Posted: Mar 20, 2004 1:36 AM
Reply to this message Reply
Advertisement
I have basic question about functions. For example I have 2 functions called FunctionA() and FunctionB(). 1. FunctionA() is calling FunctionB(). 2. FunctionA() called by main function. Now my question is the compiler or debugger know which function it start with and which function it has to call and from where its called all those information at compile time this things are in the stack as function points or based on the function's address the calls are made, but here my question in run time is there any way the FunctionB() or FunctionA() know that FunctionA() and main() functions are calling? please let me if there is a way. Thanks in advance.


Hagrid

Posts: 4
Nickname: hagrid
Registered: Sep, 2003

Re: Who Called Me? Posted: Mar 20, 2004 10:25 AM
Reply to this message Reply
As far as I know there is only one way to do this in Java: create an exception in your function and examine the stack trace elements of it (see javadoc).
But be aware that creating an exception is a heavy (time consuming) operation for the VM.

Marie Tessier

Posts: 2
Nickname: marie
Registered: Mar, 2004

Re: Who Called Me? Posted: Mar 21, 2004 4:56 PM
Reply to this message Reply
You do not have to make an exception, you can just make an instantiation of 'Throwable', do a 'fillInStackTrace()', then do a 'getStackTrace()', and then pick apart the appropriate StackTraceElement. There are probably simpler ways, but that is somewhere to start.

Balasubramanian Natarajan

Posts: 2
Nickname: pranavbala
Registered: Mar, 2004

Re: Who Called Me? Posted: Mar 22, 2004 8:50 AM
Reply to this message Reply
> You do not have to make an exception, you can just make an
> instantiation of 'Throwable', do a 'fillInStackTrace()',
> then do a 'getStackTrace()', and then pick apart the
> appropriate StackTraceElement. There are probably simpler
> ways, but that is somewhere to start.

> You do not have to make an exception, you can just make an
> instantiation of 'Throwable', do a 'fillInStackTrace()',
> then do a 'getStackTrace()', and then pick apart the
> appropriate StackTraceElement. There are probably simpler
> ways, but that is somewhere to start.

Thanks for your reply. Do you have any idea about these similar functions are in C/C++?

Flat View: This topic has 3 replies on 1 page
Topic: How I stop to creat another instance of appl if one is already open Previous Topic   Next Topic Topic: how to operate macro using java ?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use