Is it wise to use generics for exceptions?

Viewed 18746

My team is in the middle of cleaning up our use of throws Exception and either removing or replacing them with specific exceptions.

A common throws is because an entity was not found. Should we be throwing a generic NotFoundException or a specific SomeClassNotFoundException for each entity class?

If we should be throwing a specific exception, should we be creating a specific Exception class for each entity type? Can we safely use generics? Like this class NotFoundException<T extends EntityBaseClass> extends Exception and then the constructor takes care of declaring what Entity type we're dealing with?

If we should be throwing a specific exception and not using generics, should those exceptions extend or implement a NotFoundException abstract class or interface?

5 Answers
Related