Skip to content

Instantly share code, notes, and snippets.

@showsky
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save showsky/5c258d8cf66e8e0f15ff to your computer and use it in GitHub Desktop.

Select an option

Save showsky/5c258d8cf66e8e0f15ff to your computer and use it in GitHub Desktop.
AsyncTask handling excpetion
public class AsyncResult<T> {
public T result;
public Excpetion excpetion;
}
-----
@Override
protected final AsyncResult<T> doInBackground(Void... params) {
Result<T> result = new Result<T>();
try {
result.result = xxxxxx;
} catch (Exception exc) {
result.exc = exc;
}
return result;
}
@Override
protected final void onPostExecute(AsyncResult<R> result) {
if (result.excpetion != null) {
// ... alert the user ...
} else {
// ... success, continue as normal ...
}
}
-----
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment