HiveBrain v1.2.0
Get Started
← Back to all entries
debugjavaCritical

Difference between using Throwable and Exception in a try catch

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
throwableandbetweenusingdifferenceexceptioncatchtry

Problem

Sometimes, I see

try {

} catch(Throwable e) {

}


And sometimes

try {

} catch(Exception e) {

}


What is the difference?

Solution

By catching Throwable it includes things that subclass Error. You should generally not do that, except perhaps at the very highest "catch all" level of a thread where you want to log or otherwise handle absolutely everything that can go wrong. It would be more typical in a framework type application (for example an application server or a testing framework) where it can be running unknown code and should not be affected by anything that goes wrong with that code, as much as possible.

Context

Stack Overflow Q#2274102, score: 370

Revisions (0)

No revisions yet.