Printing a stack trace.

I find myself needing to print a stack trace at certain points within my Java application (I'm trying to debug a race condition). Now I did most of my Java programming between 1996-99 and I'm now just returning to it, so I'm hoping that there is a simple answer to this and it's common knowledge for the Java cognascenti.

I'm currently using an "old" method I wrote for generating a stack trace:

       
      public final static void
      printStack() {
          new Exception("Stack trace").printStackTrace();
      }
      

But that will print the whole stack trace. Every single frame. I'm looking for a variant where I can pass in an argument that specifies the number of frames I'd like printed. It doesn't seem to be a standard part of the language. Certainly not from looking at the JavaDoc for the Throwable class.

I'm guessing somebody has "been there, done that" in the last five years. Can anybody point me at such a beast? Thanks.

[]

Comments:

Post a Comment:
Comments are closed for this entry.
About

user12607856

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today