Reputation: 51
I try to develop under Android. Now I try to use network.
I have the "manager class"
private String makeQuery(String string){
Log.d("makeQuery", "in");
try{
NetTask a = new NetTask(server_url);
}catch(IOException e){
Log.d("makeQuery", "exception");
}
Log.d("makeQuery", "out");
return "string";
}
It have the method for queries to my own API server over HTTP. It uses NetTask object, NetTask inheritance AsyncTask
public class NetTask extends AsyncTask<String, Void, Void> {
HttpURLConnection connection;
public NetTask(URL server) throws IOException{
Log.d("NetTask", "Create");
connection = (HttpURLConnection)server.openConnection();
connection.setReadTimeout(10000);
connection.setConnectTimeout(15000);
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.setDoOutput(true);
Log.d("NetTask", "Connect");
connection.connect();
Log.d("NetTask", "Response");
int response = connection.getResponseCode();
Log.d("NetTask", "The response is: " + response);
}
In my case I get next logs:
[makeQuery]
[NetTask]
So, why line Log.d("makeQuery", "out"); is not reachable?
Upvotes: 0
Views: 99
Reputation: 126445
Why Log.d("makeQuery", "out");
is un reachable?
try{
NetTask a = new NetTask(server_url);
}catch(IOException e){
Log.d("makeQuery", "exception");
}
The reason is that NetTask
class throws other kind of exception.
you will change to
}catch(Exception e){
Log.d("makeQuery", "exception");
}
but the good practice says catch the correct Exception, comment the exception handling and look into your LogCat for the type of Exception.
Upvotes: 1