Search code examples
javaexceptionthrowable

Is it a bad practice to catch Throwable?


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?


Solution

  • 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.