记录每个方法抛出的所有异常

这是严重使用不足。大多数公共 API 都没有 @throws Java 文档来解释抛出的异常。

这是一个很好的例子。

...
 *
 * @throws MalformedURLException The formal system identifier of a
 * subordinate catalog cannot be turned into a valid URL.
 * @throws IOException Error reading subordinate catalog file.
 */
public String resolveSystem(String systemId)
  throws MalformedURLException, IOException {
...

这是一个缺乏有关在什么情况下抛出异常的信息的坏例子。

 * @throws Exception exception
 */
public void startServer() throws Exception {
    if (!externalDatabaseHost) {
本文转载于:https://www.yisu.com/zixun/276112.html 如有侵犯,请联系zhengruancom@outlook.com删除。
免责声明:正软商城发布此文仅为传递信息,不代表正软商城认同其观点或证实其描述。