Giter Club home page Giter Club logo

Comments (13)

branflake2267 avatar branflake2267 commented on August 16, 2024

That sounds like a great idea.

from gwtp.

kuhnroyal avatar kuhnroyal commented on August 16, 2024

I am already on that :)

from gwtp.

christiangoudreau avatar christiangoudreau commented on August 16, 2024

Uh, yeah! LOL That was so obvious that I didn't think about it!

from gwtp.

jbarop avatar jbarop commented on August 16, 2024

👍

kuhnroyal, cool!
Some way to set an UncaughtExceptionHandler would be really great. I'll use this in the development enviroment to display exceptions:

public class ApplicationDevEntryPoint extends ApplicationEntryPoint {

  private static final Logger LOG = Logger.getLogger(ApplicationDevEntryPoint.class.getName());

  @Override
  public void onModuleLoad() {
    GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
      @Override
      public void onUncaughtException(final Throwable e) {
        LOG.severe(getStacktrace(e));
        GWT.log("UncaughtException!", e);
        showExceptionPopup(e);
      }
    });

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
      @Override
      public void execute() {
        ApplicationDevEntryPoint.super.onModuleLoad();
      }
    });
  }

  /**
   * @return A quote which should scare the developer.
   */
  private String getQuote() {
    String quote = "";

    quote += "[The crew waits quietly as a Reaver ship passes.] \n";
    quote += "Simon: What happens if they board us?  \n";
    quote += "Zoe:   If they take the ship, they'll rape us to death, eat our flesh, and sew our skins into their clothing. \n";
    quote += "       And if we're very, very lucky they'll do it in that order. \n\n";

    return quote;
  }

  /**
   * @return The stacktrace to the given exception.
   */
  private String getStacktrace(final Throwable throwable) {
    String stacktrace = "";
    Throwable cur = throwable;

    while (cur != null) {
      StackTraceElement[] stackTraceElements = cur.getStackTrace();
      stacktrace += cur.toString() + "\n";
      for (int i = 0; i < stackTraceElements.length; i++) {
        stacktrace += "    at " + stackTraceElements[i] + "\n";
      }
      cur = cur.getCause();
      if (cur != null) {
        stacktrace += "Caused by: ";
      }
    }

    return stacktrace;
  }

  /**
   * Shows the given exception to the user.
   */
  private void showExceptionPopup(final Throwable e) {
    String output = getQuote() + getStacktrace(e);

    DialogBox dialogBox = new DialogBox(true, false);
    DOM.setStyleAttribute(dialogBox.getElement(), "backgroundColor", "#ABCDEF");
    dialogBox.setHTML("<pre style='font-family: monospace; font-size: 0.8em; margin: 0; padding: 10px;'>"
        + output + "</pre>");
    dialogBox.center();
  }

}

from gwtp.

branflake2267 avatar branflake2267 commented on August 16, 2024

@jbarop I like this idea, but it has disadvantages too if your not aware its being used. Maybe this could be separate issue. Could you move this idea of using a handler to catch exceptions into a new issue? :)

from gwtp.

christiangoudreau avatar christiangoudreau commented on August 16, 2024

Couldn't this be done inside an eagerSingleton class? I'm usually installing classes as eagerSingleton for that kind of thing. (Like calling all the ensure injected on my style classes)

from gwtp.

jbarop avatar jbarop commented on August 16, 2024

branflake2267, agreed (moved to #103 )

christiangoudreau, I think this will not work as expected because only the next JS event cycle will use the new handler. The excpetions thrown during initialization of the app will be catched by the default handler.

the basic workflow is to set the handler and boot the app in a derefered command (which will happen in a new event cycle).

from gwtp.

kuhnroyal avatar kuhnroyal commented on August 16, 2024

Yea I have a similar setup, I'll see what I can come up with.

from gwtp.

kuhnroyal avatar kuhnroyal commented on August 16, 2024

Implemented in samples ArcBees/GWTP-Samples#16

EntryPoints can not be generated since there is no call to GWT.create() but MvpWithEntryPoint.gwt.xml now uses the default ClientEntryPoint thus removing the need to add one to your App.

from gwtp.

branflake2267 avatar branflake2267 commented on August 16, 2024

Would you say this is ready to close?

from gwtp.

kuhnroyal avatar kuhnroyal commented on August 16, 2024

Well yes, once #106 is pulled :)

from gwtp.

kuhnroyal avatar kuhnroyal commented on August 16, 2024

Nevermind, yes this can be closed!

from gwtp.

branflake2267 avatar branflake2267 commented on August 16, 2024

Nice work everyone!!!

from gwtp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.