简体   繁体   English

如何处理 GWT/GXT 中的客户端异常?

[英]How to handle client side exceptions in GWT/GXT?

I am using GWT.我正在使用 GWT。 if any server side exception is generated, we are sending an email with error details(have used log4j SMTPAppender).如果生成任何服务器端异常,我们将发送一封包含错误详细信息的电子邮件(已使用 log4j SMTPAppender)。 Based on the line number, we can fix the issue..根据行号,我们可以解决问题..

My scenario is, if any exception is generated in the client package code, as of now, we are giving generic message saying "Some Exception has Occured".我的情况是,如果在客户端包代码中生成任何异常,截至目前,我们将给出通用消息“发生了某些异常”。 But is it possible to display error stack trace along with the exception cause and line number?但是是否可以显示错误堆栈跟踪以及异常原因和行号? my code is as below:我的代码如下:

 GWT.setUncaughtExceptionHandler(new   
                      GWT.UncaughtExceptionHandler() {  
                      public void onUncaughtException(Throwable e) {  

                          Window.alert("Some Exception has Occured");

                      }    


                    });  

I dont think it is possible as client package is converted into Javascript in web mode.我认为这是不可能的,因为客户端包在 Web 模式下被转换为 Javascript。 Please suggest me if there is any approach to display exception cause and line number where it has occured.请建议我是否有任何方法可以显示异常原因和发生的行号。

You can read this page你可以阅读这个页面

Basically, you have to use JUL to do your logging, and it's client logging : firebug, JS console, etc... You may do some smarter things with the RemoteLogging but i can't help you on that.基本上,你必须使用 JUL 来做你的日志记录,它是客户端日志记录:firebug、JS 控制台等......你可以用 RemoteLogging 做一些更聪明的事情,但我无法帮助你。

The main problem is that log4j is not supported.主要问题是不支持 log4j。 Maybe with a bridge between JUL and log4j you will be able to achieve everything you want也许通过 JUL 和 log4j 之间的桥梁,您将能够实现您想要的一切

I would recommend using gwt-log: Project Page我建议使用 gwt-log:项目页面

gwt-log has support for an 'UncaughtExceptionHandler' and a RemoteLogger to send messages/exception to the server. gwt-log 支持“UncaughtExceptionHandler”和 RemoteLogger 来向服务器发送消息/异常。

in gwt-log, you can also turn on the "emulated stack", which is exactly what you want to do: Wiki Page - Emulated Stack在gwt-log中,你也可以开启“模拟堆栈”,这正是你想要做的: 维基页面 - 模拟堆栈

please note however that this adds a LOT of code to the compiled JS-script但是请注意,这会向编译的 JS 脚本添加大量代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM