When to choose checked and unchecked exceptions

前端 未结 18 2268
南方客
南方客 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:06

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

    From the point of view of the developer using your library or the end-user using your library/application it really sucks to be confronted with an application that crashes due to an uncought exception. And counting on a catch-all is no good either.

    This way the end user can still be presented with an error message, instead of the application completely disappearing.

提交回复
热议问题