由于不同帖子Throwable
中列出的原因,不建议抓捕。但是,有一个像下面这样的主要结构有意义吗?如果删除 Throwable 行,则不会记录错误。
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);
}
}