Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

determine calling function, java file, linenumber

Posted on 2004-10-31
6
Medium Priority
?
371 Views
Last Modified: 2008-01-09
is it possible from within my function body, to find the calling function, line number, java file ?

thanks :)
muskad202
0
Comment
Question by:muskad202
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
lwinkenb earned 80 total points
ID: 12456131
You can use Thread.dumpStack() to dump the thread's stack.
0
 
LVL 2

Author Comment

by:muskad202
ID: 12456271
Thread.dumpStack() would print the entire thing to the console ... i'm looking for something that i can use programatically (e.g., if calling function == "some function" then do something) ..
thanks anywayz :)
0
 
LVL 4

Expert Comment

by:lcwiding
ID: 12456331
Actually, dumpStack() can work, but you first need to redirect System.out to a stream object that you define, so that you can monitor what is printed there. Generally, your filter could just echo to the console, and when a flag is set, copy the stack dump to a vector for later processing. Something like:

class MyPrintStream extends PrintStream
{
    PrintStream copy = null;
    PrintStream out;

   public MyPrintStream(PrintStream out)
   {
      this.out = out;
   }

   //
   // use this as a model for as many of the PrintStream methods as you feel need to be filtered.
   //
   public void write(int b)
   {
      out.write(b);
      if (copy != null)
      {
         copy.write(b);
      }
   }

   public setCopy(PrintStream copy)
   {
      this.copy = copy;
   }
}

MyPrintStream mps = new MyPrintStream(System.out);
System.setOut(mps);

//
// when it is time to check the call stack
//
ByteArrayOutputStream boas = new ByteArrayOutputStream();
mps.setCopy(new PrintStream(boas));
new Exception().printStrackTrace();
mps.setCopy(nuill);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Author Comment

by:muskad202
ID: 12456472
was thinking along similar lines ... but the idea is certainly "innovative" :)
thanks :D
muskad202
0
 
LVL 2

Author Comment

by:muskad202
ID: 12456474
one thing .. how do I revert back to the standard output stream ?
0
 
LVL 4

Expert Comment

by:lcwiding
ID: 12456908
You can revert to the standard output stream with:

System.setOut(mps.out);
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question