title: how to treat internet connection issue in android
body: <p>I've researched most of the questions here but did not find a viable solution.</p>
  
  <p>I'm designing an app that highly uses internet connection. I permanently need to request/receive information from a web service. </p>
  
  <p>I've tried sourounding all code that uses internet with </p>
  
  <pre><code>    try
      {
         //use of internet here
      }
     catch (Exception e)
     {
            //Alert dialog that states internet connection is down
     }
  </code></pre>
  
  <p>but this doesn't seem to work. The exception is not catched here for some reason.</p>
  
  <p>I've tried a workaround, a solution i found here. Use of:</p>
  
  <pre><code> public static boolean isOnline(Context context) {
      ConnectivityManager cm =(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo netInfo = cm.getActiveNetworkInfo();
      if (netInfo != null &amp;&amp; netInfo.isConnectedOrConnecting()) {
          return true;
      }
      return false;
  }
  </code></pre>
  
  <p>And use it like :</p>
  
  <pre><code>        if (Utilities.IsOnline(context))
           {
            //Code that uses internet
           }
  </code></pre>
  
  <p>What happens if the connection is lost right after the IsOnline check?
  How can i treat this case?
  Thank you!</p>