Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8264121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:20:53+00:00 2026-06-08T04:20:53+00:00

I have a scenario in Spring MVC , where I have to throw an

  • 0

I have a scenario in Spring MVC , where I have to throw an Exception explicitly in the handleRequest Method.

For Eg.

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");

     }

Now assuming that spring servlet and url mapping is configured in web.xml, when i try to access the servlet via url http://localhost:8080/server/admin?reqParam=xyz, I get an correct error on page. java.lang.Exception: Undeploy failed....

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.

Code is :

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();

Can you please let me know where the changes should be done so that the exception on the Client could be caught.

I could google but couldnt find a appropriate answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T04:20:54+00:00Added an answer on June 8, 2026 at 4:20 am

    Exceptions can’t be thrown over HTTP. What you’ll need to do is:

    1. On the server side, handle the exception and make sure your HTTP response has an appropriate statusCode and/or response header/body.

    2. On the client side, translate that response into the exception you want.

    You should investigate what interfaces HttpClient provides for exception handling.

    My answer to this question might help you with the server side:

    https://stackoverflow.com/a/11535691/1506440

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Spring MVC application which has a public front-end WAR, an admin
I'm playing around with Razor + MVC 3 and have a really simple scenario...
I have problem with the autoload function here is the scenario: Note: the MVC
I have a model that looks something like this: public class SampleModel { public
Scenario: We have a Spring managed web application that runs inside Websphere. (Spring 3.0.x,
I'm using Spring MVC and have to implement session tracking through programatically. When user
I have two Spring contexts declared in my application - one for Spring-MVC requests,
I have a strange scenario in which my controller is not invoked unless I
Problem: We have a Spring MVC-based RESTful API which contains sensitive information. The API
I have a confusing scenario regarding transaction rollbacks with Spring. I am successfully creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.