Should methods that throw RuntimeException indicate it in method signature?

后端 未结 7 1709
小鲜肉
小鲜肉 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:00

    This has to do with the discussion regarding checked exceptions. Most would agree that exceptions shouldn't be declared in methods signatures.

    There is also a discussion regarding how runtime exceptions should be used. I agree with one poster that runtime exceptions should denote a programming error or a fatal condition. So there isn't much merit declaring them in the signature. Every method could potentially through one.

提交回复
热议问题