private void addProxyCheckException ( TypeSpec . Builder classBuilder ) { MethodSpec . Builder methodBuilder = MethodSpec . methodBuilder ( "checkException" ) . addModifiers ( Modifier . PRIVATE ) . returns ( Throwable . class ) . addParameter ( ClassName . get ( "android.os" , "Parcel" ) , "reply" ) . addStatement ( "int code = reply.readInt()" ) . addStatement ( "Throwable exception = null" ) . beginControlFlow ( "if (code != 0)" ) . addStatement ( "String msg = reply.readString()" ) . beginControlFlow ( "if (code == REMOTER_EXCEPTION_CODE)" ) . addStatement ( "exception = (Throwable) reply.readSerializable()" ) . endControlFlow ( ) . beginControlFlow ( "else" ) . addStatement ( "exception = new RuntimeException(msg)" ) . endControlFlow ( ) . endControlFlow ( ) . addStatement ( "return exception" ) ; classBuilder . addMethod ( methodBuilder . build ( ) ) ; }
Add proxy method to check for exception