0

I am developing an android app that reads a webpage using AsyncTask.I have 2 AsyncTask classes that reads different page, one inside service, other not.In both cases url connection method is enclosed inside try-catch block , but their catch blocks are different(TimeoutException catch block missing in the 2nd AsyncTask class, tried to catch or throw it manually but failed) .Even though their connection methods are same, their try-catch blocks are different, but I need to catch TimeoutException in both task. Here is part of my 1st AsyncTask class

try {
    url=new URL(link);
    huc=(HttpURLConnection) url.openConnection();
    huc.setRequestMethod("GET");
    huc.setDoOutput(true);
    huc.setReadTimeout(READ_TIMEOUT);
    huc.connect();
    dothework();
} catch (IOException e) {
    e.printStackTrace();
} catch (TimeoutException e) {
    showErrorMsg();
    e.printStackTrace();
}

and part of 2nd AsyncTask class

try {
    url = new URL(link);
    HttpURLConnection huc=(HttpURLConnection) url.openConnection();
    huc.setReadTimeout(5000);
    huc.setDoOutput(true);
    huc.setRequestMethod("GET");
    huc.connect();
}catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
    e.printStackTrace();
    }
Ravi Yenugu
  • 3,895
  • 5
  • 40
  • 58
The_ehT
  • 1,202
  • 17
  • 32

1 Answers1

0

I'm not sure, but I think a HttpConnection is a AsyncTask already. So, I think you're making a call to an AsyncTask inside another.

Víctor Martín
  • 3,352
  • 7
  • 48
  • 94