gpt4 book ai didi

java - 使用 RuntimeExceptions 和 CheckedExceptions

转载 作者:搜寻专家 更新时间:2023-11-01 01:00:57 26 4
gpt4 key购买 nike

您对在应用程序中使用 CheckedExceptions 和 RuntimeExceptions 有何看法?有人建议我结合使用两者,据我所知,您可以将 CheckedException 调用链与 RuntimeException 一起传播。

最佳答案

仅当您可以合理地期望调用者处理它们时,才应抛出已检查的异常。否则抛出 RuntimeException(不需要您声明它或处理程序捕获它。这是 Spring JDBC 采用的方法)。

来自 Sun 的更多详细信息 here .

If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make it an unchecked exception.

关于java - 使用 RuntimeExceptions 和 CheckedExceptions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1913659/

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