What is the general rule of thumbs for creating an Exception in Java?

后端 未结 8 1011
悲哀的现实
悲哀的现实 2021-01-07 19:04

I have been in both situations:

  • Creating too many custom Exceptions
  • Using too many general Exception class

In both cases the project s

8条回答
  •  南笙
    南笙 (楼主)
    2021-01-07 19:33

    The Java Specialists wrote a post about Exceptions in Java, and in it they list a few "best practices" for creating Exceptions, summarized below:

    • Don't Write Own Exceptions (there are lots of useful Exceptions that are already part of the Java API)

    • Write Useful Exceptions (if you have to write your own Exceptions, make sure they provide useful information about the problem that occurred)

提交回复
热议问题