I created one Rest service and wanted to implement exception handling, but it throws a mapMappableContainerException while I try to start the services. You can find my code here.
MyService:
@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("add")
public Response addJobSeeker() throws MyCustomException{
throw new MyCustomException("My Exception");
}
My exception class.
@Provider
public class MyExceptionMapper extends Exception implements ExceptionMapper<MyCustomException>{
private static final long serialVersionUID = 1L;
public MyExceptionMapper(String str){
super(str);
}
@Override
public Response toResponse(MyCustomException exception) {
System.out.println("In my exception mapper -- "+exception.getMessage());
Success sc = new Success(404, "Hello", "I am mukesh");
return Response.status(404).entity(sc).type(MediaType.APPLICATION_JSON).build();
}
}
Mycustomclass
public class MyCustomException extends Exception {
private static final long serialVersionUID = 1L;
public MyCustomException(String str){
super(str);
}
source
share