Skip to content

Commit 0fb5ca3

Browse files
committed
Merge pull request androidannotations#682 from tbruyelle/646_PropagateThreadExceptions
Remove try/catch block on @Background/@UIThread methods
2 parents 4b0abd6 + 4a6a77b commit 0fb5ca3

2 files changed

Lines changed: 2 additions & 26 deletions

File tree

AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/APTCodeModelHelper.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@
3737
import javax.lang.model.type.WildcardType;
3838

3939
import org.androidannotations.processing.EBeanHolder;
40-
import org.androidannotations.processing.EBeansHolder.Classes;
4140

4241
import com.sun.codemodel.JBlock;
43-
import com.sun.codemodel.JCatchBlock;
4442
import com.sun.codemodel.JClass;
4543
import com.sun.codemodel.JClassAlreadyExistsException;
4644
import com.sun.codemodel.JCodeModel;
@@ -54,7 +52,6 @@
5452
import com.sun.codemodel.JMethod;
5553
import com.sun.codemodel.JMod;
5654
import com.sun.codemodel.JStatement;
57-
import com.sun.codemodel.JTryBlock;
5855
import com.sun.codemodel.JType;
5956
import com.sun.codemodel.JVar;
6057

@@ -228,27 +225,9 @@ public String getIdStringFromIdFieldRef(JFieldRef idRef) {
228225
throw new IllegalStateException("Unable to extract target name from JFieldRef");
229226
}
230227

231-
public JTryBlock surroundWithTryCatch(EBeanHolder holder, JBlock block, JBlock content, String exceptionMessage, boolean propagate) {
232-
Classes classes = holder.classes();
233-
JTryBlock tryBlock = block._try();
234-
tryBlock.body().add(content);
235-
JCatchBlock catchBlock = tryBlock._catch(classes.RUNTIME_EXCEPTION);
236-
JVar exceptionParam = catchBlock.param("e");
237-
JInvocation errorInvoke = classes.LOG.staticInvoke("e");
238-
errorInvoke.arg(holder.generatedClass.name());
239-
errorInvoke.arg(exceptionMessage);
240-
errorInvoke.arg(exceptionParam);
241-
catchBlock.body().add(errorInvoke);
242-
if (propagate) {
243-
catchBlock.body()._throw(exceptionParam);
244-
}
245-
return tryBlock;
246-
}
247-
248228
public JDefinedClass createDelegatingAnonymousRunnableClass(EBeanHolder holder, JMethod delegatedMethod) {
249229

250230
JCodeModel codeModel = holder.codeModel();
251-
Classes classes = holder.classes();
252231

253232
JDefinedClass anonymousRunnableClass;
254233
JBlock previousMethodBody = removeBody(delegatedMethod);
@@ -258,9 +237,7 @@ public JDefinedClass createDelegatingAnonymousRunnableClass(EBeanHolder holder,
258237
JMethod runMethod = anonymousRunnableClass.method(JMod.PUBLIC, codeModel.VOID, "run");
259238
runMethod.annotate(Override.class);
260239

261-
JBlock runMethodBody = runMethod.body();
262-
263-
surroundWithTryCatch(holder, runMethodBody, previousMethodBody, "A runtime exception was thrown while executing code in a runnable", true);
240+
runMethod.body().add( previousMethodBody );
264241

265242
return anonymousRunnableClass;
266243
}

AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/BackgroundProcessor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) t
6060
JMethod executeMethod = anonymousTaskClass.method(JMod.PUBLIC, codeModel.VOID, "execute");
6161
executeMethod.annotate(Override.class);
6262

63-
JBlock runMethodBody = executeMethod.body();
64-
helper.surroundWithTryCatch(holder, runMethodBody, previousMethodBody, "A runtime exception was thrown while executing code in a background task", true);
63+
executeMethod.body().add( previousMethodBody );
6564

6665
Background annotation = element.getAnnotation(Background.class);
6766
String id = annotation.id();

0 commit comments

Comments
 (0)