package uk.co.prenderj.trail.util;

import android.os.AsyncTask;

public abstract class CheckedAsyncTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
    private Exception thrown;
    
    public abstract Result call(Params... params) throws Exception;
    
    public abstract void finish(Result result) throws Exception;
    
    @Override
    protected Result doInBackground(Params... params) {
        try {
            return call(params);
        } catch (Exception e) {
            thrown = e;
            return null;
        }
    }
    
    @Override
    protected void onPostExecute(Result result) {
        if (thrown != null) {
            onException(thrown);
        }
        try {
            finish(result);
        } catch (Exception e) {
            onException(e);
        }
    }
    
    public void onException(Exception thrown) {
        cancel(true);
    }
}

@@ -174,43 +174,8 @@
 %3E %7B%0A
-    private Exception thrown;%0A    %0A
     
@@ -478,18 +478,22 @@
     
-thrown = e
+onException(e)
 ;%0A  
@@ -604,81 +604,8 @@
 ) %7B%0A
-        if (thrown != null) %7B%0A            onException(thrown);%0A        %7D%0A
     

Handle exception straight away