Thursday, May 29, 2008
Miscellaneous Java Code
Fetching Line Number in Java Code
1.
new Throwable()).getStackTrace()[0].getLineNumber()
2.
StackTraceElement[] st = Thread.currentThread().getStackTrace();
int lineNumber = st [st.length-1].getLineNumber();
Getting a stack trace can be slow. Using this to do logging can adversely effect the performance of an application.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment