You can write one ExceptionMapper against a superclass of exceptions (i.e. java.lang.Exception ), and then provide different types of behavior based on a specific class of exceptions, for example:
public class MyExceptionMapper implements ExceptionMapper<Exception> { @Override public Response toResponse(Exception exception) { if (exception instanceof EntityNotFoundException) { ... } else (exception instanceof NumberFormatException) { ... } else {
But, in my opinion, this is not as clean as writing separate cartographers for each type of exception. Firstly, this cartographer will catch all Exceptions, and for another, this class can increase to cumbersome measurements over time. Perhaps this is a code style issue.
sherb source share