zoukankan      html  css  js  c++  java
  • Effective Java 62 Document all exceptions thrown by each method

    Principle

    1. Always declare checked exceptions individually, and document precisely the conditions under which each one is thrown using the Javadoc @throws tag.
    2. A well-documented list of the unchecked exceptions that a method can throw effectively describes the preconditions for its successful execution.
    3. It is particularly important that methods in interfaces document the unchecked exceptions they may throw. This documentation forms a part of the interface's general contract and enables common behavior among multiple implementations of the interface.
    4. Use the Javadoc @throws tag to document each unchecked exception that a method can throw, but do not use the throws keyword to include unchecked exceptions in the method declaration.
    5. If an exception is thrown by many methods in a class for the same reason, it is acceptable to document the exception in the class's documentation comment rather than documenting it individually for each method. (e.g. All methods in this class throw a NullPointerException if a null object reference is passed in any parameter," or words to that effect.)

    Summary

    Document every exception that can be thrown by each method that you write. This is true for unchecked as well as checked exceptions, and for abstract as well as concrete methods. Provide individual throws clauses for each checked exception and do not provide throws clauses for unchecked exceptions. If you fail to document the exceptions that your methods can throw, it will be difficult or impossible for others to make effective use of your classes and interfaces.

  • 相关阅读:
    python操作Excel模块openpyxl
    【转】用python读写excel的强大工具:openpyxl
    Python 保存数据的方法:
    【Python】使用POST方式抓取有道翻译结果
    python3以post方式提交数据
    python3.0与python2.0有哪些不同
    清理
    汇编学习(五)——表处理程序
    智能车学习(十五)——K60野火2013版例程
    通信原理实践(六)——基带传输
  • 原文地址:https://www.cnblogs.com/haokaibo/p/document-all-exceptions-thrown-by-each-method.html
Copyright © 2011-2022 走看看