提交 187731fd 编写于 作者: J Jesse Glick

Check for printStackTrace overrides.

上级 da541716
......@@ -1457,7 +1457,12 @@ public class Functions {
return s.toString();
}
private static void doPrintStackTrace(@Nonnull StringBuilder s, @Nonnull Throwable t, @CheckForNull Throwable higher, @Nonnull String prefix) {
// TODO check if t overrides printStackTrace
if (Util.isOverridden(Throwable.class, t.getClass(), "printStackTrace", PrintWriter.class)) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
s.append(sw.toString());
return;
}
Throwable lower = t.getCause();
if (lower != null) {
doPrintStackTrace(s, lower, t, prefix);
......
......@@ -494,6 +494,13 @@ public class FunctionsTest {
"Caused: java.lang.IllegalStateException\n" +
"\tat p.C.method1(C.java:19)\n" +
"\tat m.Main.main(Main.java:1)\n");
// Custom printStackTrace implementations:
assertPrintThrowable(new Throwable() {
@Override
public void printStackTrace(PrintWriter s) {
s.println("Some custom exception");
}
}, "Some custom exception\n", "Some custom exception\n");
}
private static void assertPrintThrowable(Throwable t, String traditional, String custom) {
StringWriter sw = new StringWriter();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册