Question

I just wonder about best way to write custom exception name, like if I have user and i want make exception for add and delete and update, what is better using names like :

UserAddException
UserUpdateException
UserRemoveException or UserDeleteException ?

or like:

UserAdditionException
UserUpdateException
UserDeletionException

Exception name must describe what it handle, but not sure use "verb" describe the action where exception happened or "noun" as what exception itself do.

What I want to understand here the best way that make developers understand my exception usage and what to use later, and if there is pattern or standard used for Java development in this case.

Était-ce utile?

La solution

I would go with the second type of exception names. The reason why I would say that is because the exception: InstantiationException uses the noun InstantiationException. However, he most important thing is that you are consistent with the naming of exceptions and that the exception names give the development team a clear idea of what those exceptions indicate and their meaning. That is really the critical thing here.

Autres conseils

What I would do will be, use UserManagementException instead of too many names, and specify the exact cause of it in some message or error code defined additionally in the class.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top