gpt4 book ai didi

java - 捕获 Throwable 是一种不好的做法吗?

转载 作者:IT老高 更新时间:2023-10-28 11:30:48 25 4
gpt4 key购买 nike

捕获 Throwable 是一种不好的做法吗?

例如这样的:

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

这是一种不好的做法,还是我们应该尽可能具体?

最佳答案

您需要尽可能具体。否则,无法预料的错误可能会以这种方式悄悄消失。

此外,Throwable封面 Error也是usually no point of return .您不想捕获/处理它,您希望您的程序立即死亡,以便您可以正确修复它。

关于java - 捕获 Throwable 是一种不好的做法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6083248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com