File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Pretty print exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Pretty print exceptions" Watch "Pretty print exceptions" New topic

Pretty print exceptions

Rune Skjelvik

Joined: Nov 30, 2001
Posts: 2
A common solution when encountering exceptions is the "ugly" printstacktrace() in order to get enough information printed to fully understand the reason the exception occured.

Such stacktraces seldom do well in logs, and by java 1.4 there is a new method on Throwable which seems to make it easier to extract information from the exception/stacktrace...

However applications can be run on VM prior to 1.4, so this solution is not suitable...

My question ::
Does anyone know of some open source project or equivalent which deals with the problem of extracting information from exceptions, making it possible to make more reasonable logstatements than the damn printStackTrace()??
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Dear Rune,
Have you thought about dealing with de getStackTrace() method of Throwable?. The zeroth element of the StackTraceElement[] returned provides information about the last method invoked.
I think this in addition to the toString() method gives a reasonable information.

[ November 30, 2004: Message edited by: Ignacio del Valle ]

[ November 30, 2004: Message edited by: Ignacio del Valle ]
[ December 02, 2004: Message edited by: Ignacio del Valle ]

I agree. Here's the link:
subject: Pretty print exceptions
It's not a secret anymore!