Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in which namespace / package to put exceptions?

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

like image 576
Fabiano Avatar asked Apr 27 '10 11:04

Fabiano


1 Answers

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.

like image 58
Andrew Hare Avatar answered Sep 18 '22 06:09

Andrew Hare