title: throw exception as response from Spring handleRequest method
body: <p>I have a scenario in Spring MVC , where I have to throw an Exception explicitly in the handleRequest Method. </p>
  
  <p>For Eg.</p>
  
  <pre><code>public class AdminController implements Controller {
  
  public ModelAndView handleRequest(HttpServletRequest request,
          HttpServletResponse response) throws Exception {
  
     // for some request parameter this is run. For Eg. reqParam=xyz
      undeployTables();
  }
  
  public void undeployTables() throws Exception {
        throw new Exception("Undeploy Exception");
  
       }
  </code></pre>
  
  <p>Now assuming that spring servlet and url mapping is configured in web.xml, when i try to access the servlet via url  <code>http://localhost:8080/server/admin?reqParam=xyz</code>, I get an correct error on page. <code>java.lang.Exception: Undeploy failed.... </code></p>
  
  <p>But when I try to access the code via HTTPClient, that is via the java code the response in the client is not able to catch this exception and only I get is the HTTP 401 Internal Error as response object.But what i would Like to have is an Exception object in client.</p>
  
  <p>Code is : </p>
  
  <pre><code>HttpPost httppost = new HttpPost(url.toURI());
  httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, timeout);
  logger.info("executing request " + httppost.getURI()); //$NON-NLS-1$
  // Create a response handler
  HttpResponse response = httpclient.execute(httppost);// expect exception to be thrown here
  statusCode = response.getStatusLine().getStatusCode();
  </code></pre>
  
  <p>Can you please let me know where the changes should be done so that the exception on the Client could be caught.</p>
  
  <p>I could google but couldnt find a appropriate answer.</p>