Should methods that throw RuntimeException indicate it in method signature?

后端 未结 7 1695
小鲜肉
小鲜肉 2020-11-30 23:43

For example, many methods in frameworks/JDK might throw

java.lang.SecurityException 

but this is not indicated in the method signature (si

7条回答
  •  春和景丽
    2020-12-01 00:08

    In my point of view it's better to declare runtime exceptions at least in the javadoc for the method. Declaring it in the signature makes it even more obvious what may happen when something goes wrong. This is my main reason for suggesting to provide this information.

    FYI: as time has progressed (now in 2017) I am leaning now far more to documenting them in javadoc only and avoiding checked exceptions as much as possible.

提交回复
热议问题