public class ExceptionTest5 { public ExceptionTest5(){ try { test(); } catch (Exception ex) { StackTraceElement[] element = ex.getStackTrace(); System.out.println(ex.getClass().getName()); for (int i = 0 ; i < element.length ; i++) { System.out.print(" at "); System.out.print(element[i].getClassName()); System.out.print("." + element[i].getMethodName()); System.out.print("("+ element[i].getFileName()); System.out.print(":" + element[i].getLineNumber()); System.out.println(")"); } } } private void test() throws TestException { try { throw new InterruptedException(); } catch (InterruptedException ex) { throw new TestException(ex); } } public static void main(String[] args){ new ExceptionTest5(); } }