1 /* This test should test the stacktrace functionality. 2 We only print ClassName and MethName since the other information 3 like FileName and LineNumber are not consistent while building 4 native or interpreted and we want to test the output inside the dejagnu 5 test environment. 6 Also, we have to make the methods public since they might be optimized away 7 with inline's and then the -O3/-O2 execution might fail. 8 */ 9 public class stacktrace { main(String args[])10 public static void main(String args[]) { 11 try { 12 new stacktrace().a(); 13 } catch (TopException e) { 14 } 15 } 16 a()17 public void a() throws TopException { 18 try { 19 b(); 20 } catch (MiddleException e) { 21 throw new TopException(e); 22 } 23 } 24 b()25 public void b() throws MiddleException { 26 c(); 27 } 28 c()29 public void c() throws MiddleException { 30 try { 31 d(); 32 } catch (BottomException e) { 33 throw new MiddleException(e); 34 } 35 } 36 d()37 public void d() throws BottomException { 38 e(); 39 } 40 e()41 public void e() throws BottomException { 42 throw new BottomException(); 43 } 44 } 45 46 class TopException extends Exception { TopException(Throwable cause)47 TopException(Throwable cause) { 48 super(cause); 49 } 50 } 51 52 class MiddleException extends Exception { MiddleException(Throwable cause)53 MiddleException(Throwable cause) { 54 super(cause); 55 } 56 } 57 58 class BottomException extends Exception { BottomException()59 BottomException() { 60 StackTraceElement stack[] = this.getStackTrace(); 61 for (int i = 0; i < stack.length; i++) { 62 String className = stack[i].getClassName(); 63 String methodName = stack[i].getMethodName(); 64 System.out.println(className + "." + methodName); 65 } 66 } 67 } 68