Arnaud Denoyelle
Arnaud Denoyelle

Reputation: 31235

Easily get the stacktrace

In a GWT project, I sometimes struggle to understand why/when a method is called. In order to figure it out, I used to throw a dummy exception in order to catch it and access its stacktrace :

StackTraceElement[] stackTrace;
try {
  throw new NullPointerException("Dummy");
} catch (NullPointerException e) {
  stackTrace = e.getStackTrace();
}

It works but it is a bit tedious to write 6 lines just to get the stacktrace (+ the stacktrace is polluted by the dummy exception). Is there a better way?

Upvotes: 2

Views: 65

Answers (1)

Knarf
Knarf

Reputation: 2156

GWT.log("hi", new Exception("This is not a crash"));

Upvotes: 2

Related Questions