In the current package that I am working on for a project I have about 13 different custom exceptions. Is it a good idea to place these into their own subpackage below the package that has all the classes that will be using these exceptions?
For example:
com.company.project.core
contains a bunch of classes which can throw some custom exceptions which are then placed inside of
com.company.project.core.exception
The only downside I see right now is that I have few more imports for the classes using the exceptions.
I don’t think exception should go into another package, as they are connected to the other classes in your project. If a package is too crowded with many classes you should split that package, but I would prefer splitting by functional criteria.
Anyways, with so many exception-classes I would consider a base-exception-class, that can be thrown instead of multiple specialized exceptions. Something like MyProjectException.