LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-25-2005, 10:22 AM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Rep: Reputation: 83
Question java: stack trace


Is it possible to get the stack trace (to see where a method call was made) without having to raise/catch a exception? It's a pain in the neck having to do

[code]
try {
throw new Exception();
} catch (Exception e) {
e.printStackTrace();
}
|code]
 
Old 04-25-2005, 10:47 AM   #2
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Original Poster
Rep: Reputation: 83
OK.... got it. Thread.dumpStack()... but that goes to System.out. Is it possible to get it in a variable?
 
Old 04-25-2005, 11:06 AM   #3
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,483

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Try this (from JDK 1.5 only)
Code:
    StackTraceElement ste[]=Thread.currentThread().getStackTrace();
    for(int i=0; i<ste.length; i++)
    {
      System.out.println(ste[i]);
    }
 
Old 04-25-2005, 11:38 AM   #4
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Colombia
Distribution: Kubuntu, Debian, Knoppix
Posts: 1,982
Blog Entries: 1

Original Poster
Rep: Reputation: 83
Thread.getStackTrace() is not in the API I have (1.4). It belongs to Throwable. I s it available from 1.5? Maybe I have the API wrong.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference b/t Kernel stack and User stack hazzyb Linux - Software 2 09-29-2008 07:40 PM
stack trace of a process node047 Linux - Newbie 2 04-01-2005 09:11 PM
How To interpret kernel stack trace kklier Linux - Enterprise 6 08-22-2004 09:24 AM
Stack trace ust Linux - General 0 02-27-2004 02:30 AM
Trace hacker? mikeshn Linux - Security 8 04-17-2003 01:30 PM


All times are GMT -5. The time now is 12:02 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration