In which namespace / package puts exceptions

What is the general or best practice for structuring the location of your exception classes?

Let's say you have packages / namespaces myproject.person(models and DAO for faces) and myproject.order(models and DAO for orders) and exceptions PersonExceptionand OrderException. Should I put exceptions in their respective packages or in a separate package for exceptions (e.g. myproject.exceptions)?

The first approach seems more reasonable (because it is sorted by functionality). But the question is, where should you raise the exceptions related to both? e.g. aConstraintViolationException

thank

+5
source share
7 answers

, . , , , ConstraintViolationException myproject.

+8

, . - , .

+12

, Java. , API , .

+12

, . Exception jr, oun.

+1

, ( PersonException OrderException), PersonInvalidDataException PersonDataPersistException). BaseException, , .

, ( ) .

+1

(.. myproject). , , ().cs , , execeptions .

, , , , , 100 .

0

, , , , , NullPointerException, PersonException, , , , , . Person ? , - , ? - , Person ?

The fact that you are in two minds about the exceptions that apply to both objects just reinforces my problems. I suggest rethinking the design of your exceptions (EntityNotFoundException, BadArgumentException, MinorCannotOrderPornException), and the answer to your dilemma, we hope, will be more obvious.

0
source

All Articles