Is it a bad practice to catch Throwable?

ktulinho picture ktulinho · May 21, 2011 · Viewed 86.2k times · Source

Is it a bad practice to catch Throwable?

For example something like this:

try {
    // Some code
} catch(Throwable e) {
    // handle the exception
}

Is this a bad practice or we should be as specific as possible?

Answer

BalusC picture BalusC · May 21, 2011

You need to be as specific as possible. Otherwise unforeseen bugs might creep away this way.

Besides, Throwable covers Error as well and that's usually no point of return. You don't want to catch/handle that, you want your program to die immediately so that you can fix it properly.