如何使用GWT获取服务器端异常消息?

编程入门 行业动态 更新时间:2024-10-26 00:29:17
本文介绍了如何使用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

  • 实现 Serializable 和

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

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

    更多推荐

    如何使用GWT获取服务器端异常消息?

    本文发布于:2023-11-13 01:38:30,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:如何使用   服务器端   异常   消息   GWT

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!