DEV Community

Cover image for How to read and understand a Java Stacktrace

How to read and understand a Java Stacktrace

Matthew Gilliard on June 03, 2019

When things go wrong in a running Java application, often the first sign you will have is lines printed to the screen that look like this: Excep...
Collapse
 
jerrymani33 profile image
Arul

Useful post but I want to know is it okay to use try {} catch(Exception e) if we don't know or don't wanna know what gonna happen in a code block. Because of i always worried about giving try-catch block without purpose.

Collapse
 
mjg123 profile image
Matthew Gilliard Twilio • Edited

You're right - that is something to think carefully about. I think it's best to be as specific as possible. You can catch multiple types of Exception at once with syntax like this:

catch (IOException|SQLException e){...}

The only time I would catch Exception is when calling into code that you have no idea about. For example if you are allowing users to provide plugins to your app or something like that.

Collapse
 
rajakumardev profile image
Rajakumar

informative and useful, thanks for the post :)