Trapping 404 and 500 errors when using tth DefaultHTTPClient
<p>I'm using the <code>DefaultHTTPClient</code> in Android to fetch pages. I'd like to trap 500 and 404 errors returned by the server but all I get is a <code>java.io.IOException</code>. How can I specifically trap those two errors?</p>

<p>Here's my code:</p>

<pre><code>public String doGet(String strUrl, List&lt;NameValuePair&gt; lstParams) throws Exception {

    Integer intTry = 0;

    while (intTry &lt; 3) {

        intTry += 1;

        try {

            String strResponse = null;
            HttpGet htpGet = new HttpGet(strUrl);
            DefaultHttpClient dhcClient = new DefaultHttpClient();
            dhcClient.addResponseInterceptor(new MakeCacheable(), 0);
            HttpResponse resResponse = dhcClient.execute(htpGet);
            strResponse = EntityUtils.toString(resResponse.getEntity());
            return strResponse;

        } catch (Exception e) {

            if (intTry &lt; 3) {
                Log.v("generics.Indexer", String.format("Attempt #%d", intTry));
            } else {                
                throw e;                    
            }

        }

    }

    return null;

}
</code></pre>
