Friday, August 29, 2008

The first class

The snippet below prints the first class in the stacktrace. Might be useful for logging in some situations.

public vid test ()
{
Throwable th = new Throwable();
stackTraceElement[] ste = th.getStackTrace();
System.out.println(ste[ste.length -1].getClassName());
}

No comments: