Where should Exceptions used by multiple projects be used?

I need to reorganize a project with two data models into two separate projects. Both projects use the same Exceptions. Should I create a third project only for these exceptions? Cloning sounds like no.

+6
source share
4 answers

Yes, you must create it in a separate project and use it as a dependency on others. Often you can see a project / bank, in which there are only exceptions used in the modules with which you work. This is a great way to keep things organized IMHO.

+7
source

IMHO, as mentioned in an existing @harsha comment, the simplest solution would be to put the generic code in a library or .jar and a .jar file in your project library.

Now you have a valuable api that you can easily save for each build with your versions.

+1
source

Perhaps a separate project works best, which is a common dependency of the other two. Duplication of objects will be difficult if two data models are used together, which you will need to solve using, for example, different package names and which will create maintenance headaches. A shared project can be a good repository for future shared code beyond your exceptions.

+1
source

Are there only general exceptions? It sounds strange.

Is there a relationship between these projects? Is another customer?

I believe that there will also be some interfaces, some of which declare these exceptions in the signature of their methods. Some of them are implemented in one of your projects and called in another project.

If there are no such things at all, it seems that your common exceptions are simply their names! They are not the same classes, they have the same name, and since many of the user exceptions have only constructors that call super constructors, they seem to be the same.

If this is your business, I would not worry about extracting the classes, and I would keep duplicates, because nothing worked in the refactoring.

+1
source

Source: https://habr.com/ru/post/943448/


All Articles