title: Exception Mapping - org.jboss.resteasy.spi.UnhandledException: exception.DenemeException: off bu exler
body: <p>I have a restful application that imports some contacts to database. I want to throw exception when a file is not uploaded via restful. so i write an exception class DenemeException, and i want to send status 404, when i run code i get this error org.jboss.resteasy.spi.UnhandledException: exception.DenemeException: off bu exler
  can u help me pls?</p>
  
  <p>DenemeExceptionMapper.java</p>
  
  <pre><code>import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  import javax.ws.rs.ext.ExceptionMapper;
  import javax.ws.rs.ext.Provider;
  
  
  
  
  @Provider
  public class DenemeExceptionMapper implements ExceptionMapper&lt;DenemeException&gt; {
       @Override
   public Response toResponse(DenemeException ex){
       return Response.status(Response.Status.FORBIDDEN).entity(ex.getMessage()).type(MediaType.TEXT_PLAIN).build();
   }
  
  }
  </code></pre>
  
  <p>DenemeException.java</p>
  
  <pre><code>public class DenemeException extends Exception {
  /**
   * 
   */
  private static final long serialVersionUID = 1L;
  
  public DenemeException(String message) {
      super(message);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My Rest Controller</p>
  
  <pre><code>@POST
  @Path("/import")
  @Produces({"application/xml","application/json"})
  public String saveContacts (@Context HttpServletRequest request, @Context HttpServletResponse response,
           @QueryParam("alt") String alt) throws DenemeException {
  
      byte[] content = null;
  
      FileItemStream item = null;
      try{
      ServletFileUpload upload = new ServletFileUpload();
      FileItemIterator iterator = upload.getItemIterator(request);
  
      while (iterator.hasNext()) {
          item = iterator.next();
          if ("fileUpload".equals(item.getFieldName())){
  
              content = IOUtils.toByteArray(item.openStream());
  
            }
          }
      }
      catch(Exception e){
          System.out.println("hata oldu");
          throw new DenemeException("off bu exler");
      }
  </code></pre>