如何使用GWT获取服务器端异常消息? [英] How do I get the server-side exception message with GWT?

查看:187
本文介绍了如何使用GWT获取服务器端异常消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过

I tried

public void onFailure(Throwable caught) {
    Throwable cause = caught.getCause();
    String causeStr = (cause==null) ? "" : ", "+cause.getMessage();
    errorLabel.setText(SERVER_ERROR + ": " + caught.getMessage() + causeStr);

但是原因始终为空,并且 caught.getMessage()总是等于非常通用的 500服务器上的调用失败;详情请参阅服务器日志。我想从服务器抛出IllegalArgumentExceptions并能够在客户端显示它:

But cause is always null and caught.getMessage() always equals the very generic 500 The call failed on the server; see server log for details. I want to throw IllegalArgumentExceptions from the server and be able to show it on the client:

throw new IllegalArgumentException("Email address is invalid.");


推荐答案

您可以使用 com。 google.gwt.core.client.GWT.UncaughtExceptionHandler 来捕获服务器上的异常,然后抛出自己的异常

You can use com.google.gwt.core.client.GWT.UncaughtExceptionHandler to catch the exception on the server, and then throw your own exception that


  1. 实现 Serializable

在源文件夹中定义可以接受(并编译)客户端。

is defined in a source folder that is acccessible to (and compiled for) the client.

这篇关于如何使用GWT获取服务器端异常消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆