How and where do you define your own Exception hierarchy in Java?

前端 未结 5 859
广开言路
广开言路 2020-12-28 14:12

How and where do you define your own Exception hierarchy in Java?

My main question concerns package location where your Exception classes must be defined.

Do

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-28 14:33

    You can create your Exception classes wherever you want.

    The important thing is to extend an existing Exception class (java.lang.Throwable in fact). For instance java.lang.Exception or java.lang.RuntimeException. The first is a checked exception while extending RuntimeException will result in an unchecked exception; the differences between the two are detailed here.

提交回复
热议问题