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

后端 未结 8 1113
悲哀的现实
悲哀的现实 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:26

    While creating your own exception:

    • All exceptions must be a child of the Throwable Class

    • If you want to write a checked exception that is automatically enforced by the Handle or Declare Rule, you need to extend the Exception Class

    • If you want to write a runtime execption, you need to extend the Runtime Exception Class.

提交回复
热议问题