Can give me a link to that website . . . Please . . . Thanks . . .
Thomas Fritsch - 11 May 2006 12:11 GMT
> Can give me a link to that website . . . Please . . . Thanks . . .
http://mindprod.com/jgloss/trace.html
You can also try one of the following:
1) At first sight, this looks like a good solution, but I think it isn't:
Thread.getStackTrace();
This method is not guaranteed to return something usefull, and, actually, it
doesn't. The first two elements of the stack trace it returns (JDK 1.6) are
actually the method getStackTrace() itself and a helper method. You may assume
that the third element (or better the first element that is not an instance
method of Thread) is actually the one you are interested in but that may depend
on the implementation of the standard library.
2) This method is almost the same as oulan suggested, but you needn't catch the
exception:
StackTraceElement stack[] = (new Throwable()).getStackTrace();
Looks like a hack but I have actually stolen it from
java.util.LogRecord.inferCaller().
Here's a sample output:
import java.util.Arrays;
public class ST {
private static void test() {
System.out.println(
Arrays.toString(Thread.currentThread().getStackTrace()));
}
private static void test2() {
System.out.println(
Arrays.toString(new Throwable().getStackTrace()));
}
public static void main(String[] argv) {
test();
test2();
}
}
prints
[java.lang.Thread.dumpThreads(Native Method),
java.lang.Thread.getStackTrace(Thread.java:1383), ST.test(ST.java:5),
ST.main(ST.java:12)]
[ST.test2(ST.java:9), ST.main(ST.java:13)]
Cheers,
Simon
>Rodney has a snippet in his website !
I think you mean me, Roedy, and the entry you would want is
http://mindprod.com/jgloss/trace.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
oulan bator - 11 May 2006 19:27 GMT
yes, it was you, sorry for the name ...
Roedy Green - 12 May 2006 06:28 GMT
>yes, it was you, sorry for the name ...
not to worry. Almost nobody gets my name right verbally. I have
learned to respond to any name beginning with R.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 12 May 2006 06:28 GMT
>yes, it was you, sorry for the name ...
Even my mother used to sometimes call me "Roger".

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.