比如我希望打印出:
java.lang.NullPointerException
class method file (0)
但是 class method file (0) 这一行怎么也打印不出来 我也不知道为什么
谁可以帮帮我哇 200分奉上
(其实就是想要在throwable里面自定义一个额外的StackTraceElement 然后打印出来)
public class ThrowableTest {
public static void main(String[] args) {
String[] a = null;
try {
System.out.println(a[2]);
} catch (Throwable e) {
StackTraceElement[] ste = new StackTraceElement[e.getStackTrace().length+1];
ste[0] = e.getStackTrace()[0];
ste[1] = new StackTraceElement("class", "method", "file", 0);
e.setStackTrace(ste);
System.out.println(e);
}
}
}