是否可以在GWT中将堆栈跟踪打印到字符串?我认为在java.io中使用类的常用方法不起作用,因为java.io包在客户端不可用(而Writer,PrintWriter等在该包中)
谢谢
Ril*_*ark 12
我不确定StackTraceElement是否被模拟,但如果是,你可以运行类似的东西
for (StackTraceElement element : exception.getStackTrace()) {
string += element + "\n";
}
Run Code Online (Sandbox Code Playgroud)
这是我用来String
在GWT中检索完整堆栈跟踪的方法:
private static String getMessage (Throwable throwable) {
String ret="";
while (throwable!=null) {
if (throwable instanceof com.google.gwt.event.shared.UmbrellaException){
for (Throwable thr2 :((com.google.gwt.event.shared.UmbrellaException)throwable).getCauses()){
if (ret != "")
ret += "\nCaused by: ";
ret += thr2.toString();
ret += "\n at "+getMessage(thr2);
}
} else if (throwable instanceof com.google.web.bindery.event.shared.UmbrellaException){
for (Throwable thr2 :((com.google.web.bindery.event.shared.UmbrellaException)throwable).getCauses()){
if (ret != "")
ret += "\nCaused by: ";
ret += thr2.toString();
ret += "\n at "+getMessage(thr2);
}
} else {
if (ret != "")
ret += "\nCaused by: ";
ret += throwable.toString();
for (StackTraceElement sTE : throwable.getStackTrace())
ret += "\n at "+sTE;
}
throwable = throwable.getCause();
}
return ret;
}
Run Code Online (Sandbox Code Playgroud)