What is the common or best practice to structure the location of your exception classes?
Let's say you have the packages/namespaces myproject.person
(models and DAOs for persons) and myproject.order
(models and DAOs for orders) and the exceptions PersonException
and OrderException
. Should I put the exceptions in their corresponding packages or in a separate package for exceptions (e.g. myproject.exceptions
)?
The first approach seems more reasonable (because it's sorted by functionality). But there the question arises where you should put exceptions that are related to both? e.g. a ConstraintViolationException
In my experience it is best to put exceptions into the packages that make sense for that exception. I wouldn't create a special package just for exceptions - the exceptions should live near the classes that use them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With