Throwable.printStackTrace() for code comprehension

It’s been a while since I’ve been looking into Apache OpenEJB. With my recent affair with JAX-WS Web Services I thought I’d give it a try again. Not only would it help me understand the JAX-WS specification, but also would let me contribute to the project I’ve been in for a long time.

I raised the issue OPENEJB-1433 Upgrade to Apache CXF 2.3.2 and assigned it to myself.

While reading the code of the openejb-cxf module I was wondering about the many ways for code comprehension – reading the code line by line, writing junit tests, debugging, System.out.println() or…using Throwable.printStackTrace().

I’m using all of them, but for the precise understanding of the different layers of OpenEJB, the last option with Throwable.printStackTrace() turns out very productive. Throwable.printStackTrace() prints out what code executes mine as well as gives me the entire stack trace with the classes and the line numbers involved. An IDE like IntelliJ IDEA can further help out turning them into active links. It greatly eases the work.

Be Sociable, Share!
This entry was posted in Frameworks, Java EE.

One Response to Throwable.printStackTrace() for code comprehension

  1. I agree that reading the stacktrace has a great value in learning how a given piece of code works. I even suggested a way to make exception stack traces more readable.

    But I tend to put breakpoints somewhere in the code and observe stack line by line to see how the breakpoint was reached, look at parameters and local variables. IntelliJ helps with this a lot, e.g. by filtering external code or reflection from stack, but the killer feature in this IDE is dataflow analysis. Just point variable and instantly get all the possible values from all execution paths in a nice tree. I can no longer live without it ;-).

Leave a Reply

%d bloggers like this: