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
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.