title: Dismiss Progress Dialog and handle exception in AsyncTask
body: <p>I am having a trouble dismiss Progress Dialog if any exception occurs at <code>doInBackground</code> in my AsyncTask as it never reaches the onPostExecute and never dismiss the Progress Dialog which makes ANR.</p>
  
  <p><strong>Below is the code for AsyncTask</strong></p>
  
  <pre><code>   private class checkAS extends AsyncTask&lt;Void, Void, Void&gt;
  {
      ProgressDialog dialogue;
      @Override
      protected void onPostExecute() {
          // TODO Auto-generated method stub
          super.onPostExecute();
          dialogue.dismiss(); 
  
      }
      @Override
      protected Void doInBackground(Void... params) {
          //Long Network Task
          return null;
      }
      @Override
      protected void onPreExecute(Void result) {
          // TODO Auto-generated method stub
          super.onPreExecute(result);
          dialogue = new ProgressDialog(MainActivity.this);
          dialogue.setTitle("Processing");
          dialogue.setMessage("Getting Profile Information");
          dialogue.setIndeterminate(true);
          dialogue.setCancelable(false);
          dialogue.show();
      }
  }
  </code></pre>
  
  <p>My question is if any exception occurs at doInBackground how will I handle it and how onPostExecute will be called to dismiss the dialogue? I can not dismiss it on doInBackground. How to sync this up?</p>