Catching Throwable is unadvisable for reasons outlined in different posts. However, would it make sense to have a main structured like below? If the Throwable line is removed, then errors would not be logged.
public static void main(String[] args) {
try {
launchMyApplication();
} catch (SomeCheckedException e) {
//recover if you can, log it if you can't
} catch (Exception e) {
//recover if you can (unlikely), log it if you can't
} catch (Throwable e) {
//Don't try to recover, but log it
logger.error("Oops: {}", e);
}
}
Implementing this way will only handle throwables thrown on the main thread.
The best way to solve this issue is to use Thread.setDefaultUncaughtExceptionHandler().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With