Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

12
  • 8
    Because jqno's answer actually uses the Throwable.getStackTrace() method that you specified in your question, whereas Brian doesn't. He uses Throwable.printStackTrace() instead. Commented Jan 31, 2012 at 18:45
  • 10
    Just about every Java project should include Apache commons-lang. It includes many convenience methods implementing extremely common development needs. Commented Aug 15, 2013 at 21:32
  • 20
    @StijndeWitt Those three lines of code almost certainly need factoring out of the place you've called them. Since you don't know where to put them, they'll go in your utility toolbox with all the other useful snippets. Bingo! you've just reinvented guava / commons-lang / whatever... only not so well. Import a sensible utilities library instead, and save reinventing the wheel. The true sign of a novice is thinking you can do a better job than the library writers. Commented Oct 22, 2013 at 8:12
  • 9
    1. Guava has - Throwables.getStackTraceAsString(e) 2. Apache Commons Lang - ExceptionUtils.getFullStackTrace 3. Write our own custom methods Commented Mar 10, 2014 at 10:52
  • 16
    @AndrewSpencer I don't understand why you guys try so hard to bash StijndeWitt for wanting to achieve this with some small snippet. There is really not much danger in writing a tiny utility method (I don't see it as "SHEER ARROGANCE oh nooooo!! he thinks he's better than Apache!!"). There are tons of projects especially in non-Java JVM languages that really don't want to include Guava or Commons Lang just to log a stacktrace. I write Scala & Clojure libraries and certainly will not be making Apache Commons Lang a transitive dependency just for one method. Commented Mar 2, 2016 at 16:30