I have two options (which technically are the same, as I understand) to declare a custom exception class thrown only from a particular class com.XXX.Foo:
- as a public class in the package:
com.XXX.CustomException - as a public static inner class:
com.XXX.Foo.CustomException
Which option is better?
In case the exception is very specific to
Fooclass, I don’t mind keeping it as apublicNested class. And whenever it seems like a time to extract that out, simply extract that out.In general practice, I have never seen any nested class defined for Exception, though. I also don’t know if one exist in Java API.