Java示例打印异常堆栈 使用printStack()的Java示例异常 使用Thread的Java示例异常 Java示例打印异常堆栈 public class Demo { public static void main(String[] args) { try { ExceptionFunc(); } catch(Throwable e) { e.printStackTrace(); } } public static void ExceptionFunc() throws Throwable { Throwable t = new Throwable("This is new Exception in Java..."); StackTraceElement[] trace = new StackTraceElement[] { new StackTraceElement("ClassName","methodName","fileName",5) }; t.setStackTrace(trace); throw t; } } 使用printStack()的Java示例异常 使用Thread的Java示例异常