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 8203221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:28:34+00:00 2026-06-07T07:28:34+00:00

I am trying to set up my app to throw a timeout exception after

  • 0

I am trying to set up my app to throw a timeout exception after 3 seconds on the HttpPost. I am performing this request from an ASyncTask. For some reason, even when I give it a domain that doesnt exist, it hangs for about a minute or two and then throws the last exception. How come my Timeout Exceptions are not working?

protected Void doInBackground(String... params) {
            HttpPost httpPost = new HttpPost("http://hgfdhgfdhgfdhfgdhgfdhgfdhfgd.com");
            HttpParams httpParameters = new BasicHttpParams();
            HttpConnectionParams.setConnectionTimeout(httpParameters, 3000);
            HttpConnectionParams.setSoTimeout(httpParameters, 3000);
            DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
            try {
                httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse httpResponse = httpClient.execute(httpPost);
                HttpEntity httpEntity = httpResponse.getEntity();
                is =  httpEntity.getContent();  

            } catch(ConnectTimeoutException e){
                Log.e("Timeout Exception: ", e.toString());
            } catch(SocketTimeoutException ste){    
                Log.e("Timeout Exception: ", ste.toString());
            } catch (Exception e) {
                Log.e("log_tag", "Error in http connection "+e.toString());
            }

            try {
                BufferedReader br = new BufferedReader(new InputStreamReader(is));
                StringBuilder sb = new StringBuilder();
                String line = "";
                while((line=br.readLine())!=null){
                    sb.append(line+"\n");
                }
                is.close();
                result=sb.toString();
            } catch (Exception e) {
                Log.e("log_tag", "Error converting result "+e.toString());
            }
            return null;

        }
  • 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-07T07:28:35+00:00Added an answer on June 7, 2026 at 7:28 am

    Don’t call finish there.

    Why don’t you return null when there is an exception thrown with a particular error message.

    In the postexecute method, do whatever needs to be done when the result is null.

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

Sidebar

Related Questions

I'm trying to set this up where the user gives username and password in-app,
In my ruby(1.9.3) on rails (3.1) app I'm trying to set some conditional behavior
I keep running into this exception when trying to set my property phoneNumber: *
I'm trying to make a HTTP request from a Adobe Illustrator Script (this question
Im trying to set up my app to work with authlogic.. the thing is,
Trying to set up Cancan within an app of mine and having trouble with
I am trying to set a cookie in my Google App Engine page: self.response.headers.add_header('Set-Cookie','CookieName=1234;
I am trying to set the scaleMode on my AIR app. which is set
I am trying to set up a Sinatra based Ruby app to connect to
I'm trying to set up a date of birth helper in my Rails app

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.