Michael Michael - 2 months ago 15
Java Question

Exception without stack trace in Java

This is probably a very naive question.

I used to believe that a

Throwable
in
Java
always contains the stack trace. Is it correct?
Now it looks like that I catch
exceptions
without the stack trace. Does it make sense? Is it possible to catch an exception without the stack trace?

Answer

It's possible to catch a Throwable object in Java without a stack trace:

Throwable(String message, Throwable cause, boolean enableSuppression,boolean writableStackTrace) 

Constructs a new throwable with the specified detail message, cause, suppression enabled or disabled, and writable stack trace enabled or disabled.

http://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html