When to choose checked and unchecked exceptions

前端 未结 18 2647
南方客
南方客 2020-11-22 04:13

In Java (or any other language with checked exceptions), when creating your own exception class, how do you decide whether it should be checked or unchecked?

My inst

18条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 05:13

    The rule I use is: never use unchecked exceptions! (or when you don't see any way around it)

    There's a very strong case for the opposite: Never use checked exceptions. I'm reluctant to take sides in the debate but there seems to be a broad consensus that introducing checked exceptions was a wrong decision in hindsight. Please don't shoot the messenger and refer to those arguments.

提交回复
热议问题