gpt4 book ai didi

gwt - 如何在 GWT 应用程序中处理互联网连接中断的情况

转载 作者:行者123 更新时间:2023-12-03 03:39:34 24 4
gpt4 key购买 nike

我处理一个用 GWT 设计的网站,我想检查在访问该网站期间互联网连接是否中断。如果互联网出现故障,我想发送消息,因为无法连接到服务器或 Gmail 之类的东西可以处理它。

有人可以建议什么是处理这个问题的最佳方法吗?

最佳答案

这就是 AsyncCallback 上的 onFailure(Throwable t) 方法。是为了.当 RPC 由于任何原因(包括但不限于)连接丢失而失败时,会调用此方法。

由于传递给 onFailure()Throwable 可以是任何内容,因此文档中使用的模式是:

public void onFailure(Throwable caught) {
// Convenient way to find out which exception was thrown.
try {
throw caught;
} catch (IncompatibleRemoteServiceException e) {
// this client is not compatible with the server; cleanup and refresh the
// browser
} catch (InvocationException e) {
// the call didn't complete cleanly
// other Throwables may be caught here...
} catch (Throwable e) {
// last resort -- a very unexpected exception
}
}

具体来说,缺乏互联网连接将导致InvocationException传递给 onFailure()

关于gwt - 如何在 GWT 应用程序中处理互联网连接中断的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2612681/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com