日期:2014-05-20 浏览次数:20870 次
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); } } }
public static void main(String[] args) { String[] a = null; try { System.out.println(a[2]); } catch (Throwable e) { StackTraceElement[] ste = new StackTraceElement[2]; ste[0] = e.getStackTrace()[0]; ste[1] = new StackTraceElement("class", "method", "file", 0); e.setStackTrace(ste); System.out.println(e); System.out.println(e.getStackTrace()[1].toString()); } }