Throws or try-catch

后端 未结 10 1377
别跟我提以往
别跟我提以往 2020-11-28 03:15

What is the general rule of thumb when deciding whether to add a throws clause to a method or using a try-catch?

From what I\'ve read mysel

10条回答
  •  星月不相逢
    2020-11-28 03:27

    When to use what. I searched a lot about this. There is no hard and fast rule.

    "But As a developer, Checked exceptions must be included in a throws clause of the method. This is necessary for the compiler to know which exceptions to check. By convention, unchecked exceptions should not be included in a throws clause.
    Including them is considered to be poor programming practice. The compiler treats them as comments, and does no checking on them."

    Source : SCJP 6 book by Kathy Sierra

提交回复
热议问题