title: How to gracefully handle exception inside AsyncTask in Android?
body: <p>I have an <em>AsyncTask</em> to do SQLite database migration in the background (create or upgrade). Let's say somehow an <em>IOException</em> or <em>SQLiteException</em> is thrown inside <em>doInBackground</em> and it's pointless for the app to continue running because database state might be not in desired state. I'm kind of confused on what to do in this situation. </p>
  
  <p>I'm thinking about letting the application crash as soon as possible and show dialog with error message, but I'm not really sure how to this inside <em>doInBackground</em>, because: </p>
  
  <ol>
  <li>This function is not executed in UI thread so I don't know if I can show a dialog.</li>
  <li>I don't know how to access current activity within <em>AsyncTask</em>, so I can't <em>finish()</em> it.</li>
  <li>I want to somehow throw the exception to the upper layer and let an activity handle it, but it's not possible because <em>doInBackground</em> doesn't list <em>IOException</em> as a checked exception.</li>
  </ol>
  
  <p>Anyone has an advice on how to gracefully handle this situation?</p>