package test;
import java.io.PrintWriter;
import java.io.StringWriter;
public class ExceptionTest {
public static void main(String[] args) {
Exception e = new Exception("aaa", new Exception("bbb", new Exception(
"ccc", new Exception("ddd"))));
// Throwable t = e;
// while (t != null) {
// System.out.println(t.getMessage());
// t = t.getCause();
// }
e.printStackTrace();
System.out.println(getStackTrace(e));
}
public static String getStackTrace(Exception e) {
StringWriter writer = new StringWriter();
e.printStackTrace(new PrintWriter(writer, true));
return writer.toString();
}
}
java,Exception,String
最新推荐文章于 2023-07-23 17:30:17 发布