我有一个项目,该项目执行2个RPC调用,然后将用户提供的数据保存在tha数据存储区中。第一个RPC调用正常,但是从第二个开始,我总是收到onFailure()
消息。如何确定为什么触发onFailure()
?我尝试了caught.getCause()
,但未返回任何内容。
feedbackService.saveFeedback(email,studentName,usedTemplates,
new AsyncCallback<String>() {
public void onFailure(Throwable caught) {
// Show the RPC error message to the user
caught.getCause();
Window.alert("Failure!");
}
public void onSuccess(String result) {
Window.alert("Saved!");
}
});
最佳答案
Throwable实例是Exception的实例。您可以检查它是否是这样的自定义异常:
if (caught instanceOf CustomException){
或者,如果您想显示异常消息,则可以使用getMessage():
Window.alert("Failure: " + caught.getMessage());
关于gwt - 如何确定为什么在GWT-RPC中触发onFailure?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14546734/