67,513
社区成员
发帖
与我相关
我的任务
分享
Throwable t = 你捕获到的异常。
while(t!=null){
out.print("<font color='red'>");
out.print(t.getClass().getName()+ ":"+t.getMessage()+"<br/>");
out.print("</font>");
StackTraceElement[] elements = t.getStackTrace();
for(int i=0;i<elements.length;i++){
StackTraceElement e = elements[i];
out.print(" "+e.getClassName()+"#");
out.print(e.getMethodName()+"");
out.print("(line:"+e.getLineNumber()+")");
out.print("<br/>");
}
t = t.getCause();
}
public class TestException extends Exception {
private String e;
public TestException(String e){
this.e = e;
}
public String toString(){
return "抛出异常"+e;
}
}
public class Test {
public static void main(String[] args) {
String yourString="xxxxx";//这里是你说的错误信息、错误代码、函数名、文件名等等信息,要自己写的
try{
test(yourString);//执行普通函数
}catch(TestException e){
System.out.println(e);
}
}
//普通函数,在此处跑出自定义的异常
public static void test(String yourString) throws TestException{
throw new TestException(yourString);
}
}