Exceptions thrown in a task submitted to a thread pool will just disappear. You won’t even see the log.
You can catch java.lang.Exception
and handle it. But to make things even better, please catch java.lang.Throwable
instead.
In theory, it’s not recommended to catch a Throwable. But to be pragmatic, it’s important for you to see in log what happened. Otherwise, you may waste a lot of time to find the cause of a bug.
And non-Exception Throwable, i.e. java.lang.Error
does happen. A common one is ExceptionInInitializerError
, which happens when class initialization goes wrong.