Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- leadership
- Java
- history
- management
- program
- django
- hadoop
- Malaysia
- erlang
- web
- programming_book
- France
- Book
- Software Engineering
- QT
- RFID
- agile
- Book review
- comic agile
- Kuala Lumpur
- Python
- Linux
- MySQL
- hbase
- essay
- ubuntu
- Spain
- Italy
- psychology
- Programming
Archives
- Today
- Total
print stack trace(caller, callee가 알고 싶은 경우 등...) 본문
JUnit test method에서 caller가 main인 경우에는 swing 화면을 출력, JUnit test인 경우에는 출력하지 않도록 하는데 사용했음
class TestStackTrace { static class TestInnerStackTrace { // http://blog.naver.com/clean820818/10086133151 public static void method() { // print current class method StackTraceElement[] stacks = new Throwable().getStackTrace(); StackTraceElement currentStack = stacks[0]; System.out.println( "my class : " + currentStack.getClassName() ); System.out.println( "my method : " + currentStack.getMethodName() ); // print previous class method StackTraceElement[] pstacks = new Throwable().getStackTrace(); StackTraceElement beforeStack = pstacks[1]; System.out.println( "my before class : " + beforeStack.getClassName() ); System.out.println( "my before method : " + beforeStack.getMethodName() ); // print the number of stack StackTraceElement[] nstacks = new Throwable().getStackTrace(); System.out.println("stacks.length:" + nstacks.length); } } public static void main(final String[] args) { // http://cafe.naver.com/javacircle/37856 System.out.println("Printing stack trace:"); StackTraceElement[] elements = Thread.currentThread().getStackTrace(); for ( int i = 1; i < elements.length; ++i ) { StackTraceElement s = elements[i]; System.out.println("\tat " + s.getClassName() + "." + s.getMethodName() + "(" + s.getFileName() + ":" + s.getLineNumber() + ")"); } TestInnerStackTrace.method(); } }
Comments