简体   繁体   中英

How to handle client side exceptions in GWT/GXT?

I am using GWT. if any server side exception is generated, we are sending an email with error details(have used 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. 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.

The main problem is that log4j is not supported. Maybe with a bridge between JUL and log4j you will be able to achieve everything you want

I would recommend using gwt-log: Project Page

gwt-log has support for an 'UncaughtExceptionHandler' and a RemoteLogger to send messages/exception to the server.

in gwt-log, you can also turn on the "emulated stack", which is exactly what you want to do: Wiki Page - Emulated Stack

please note however that this adds a LOT of code to the compiled JS-script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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