I create a query like this. If after showError () is called. call doRequest () again, the error will not be caught and everything will fall. Tried to set global error the handler. But it does not help.

private void doRequest() { Subscription subscription = AppObservable.bindFragment(this, Observable.create(new Observable.OnSubscribe<List<Object>>() { @Override public void call(Subscriber<? super List<Object>> subscriber) { //тут происходят какие-то сетевые запросы //если все плохо, то кидается исключение //это исключение и не отлавливается при повторном выполнении этого кода subscriber.onNext(new ArrayList<>()); subscriber.onCompleted(); } })) .flatMap(getStringSelector(), getMapFunction()) .subscribe(new Action1<Boolean>() { @Override public void call(Boolean aBoolean) { if (aBoolean) { showOk(); } } }, new Action1<Throwable>() { @Override public void call(Throwable throwable) { showError(); } }); CompositeSubscription subscriptions = new CompositeSubscription(); subscriptions.add(subscription); } @NotNull private Func2<List<Object>, List<String>, Boolean> getMapFunction() { return new Func2<List<Object>, List<String>, Boolean>() { @Override public Boolean call(List<Object> objects, List<String> stringList) { if (objects.size() == 0 || stringList.size() == 0) { throw new RuntimeException(""); } return true; } }; } @NotNull private Func1<List<Object>, Observable<List<String>>> getStringSelector() { return new Func1<List<Object>, Observable<List<String>>>() { @Override public Observable<List<String>> call(List<Object> objects) { if (objects.size() == 0) { return Observable.error(new Exception("some text")); } return Observable.create(new Observable.OnSubscribe<List<String>>() { @Override public void call(Subscriber<? super List<String>> subscriber) { subscriber.onNext(new ArrayList<String>()); subscriber.onCompleted(); } }); } }; } 

UPD: error log. The actual exception is Caused by: retrofit.RetrofitError: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: should be caught and caught on the first call

 java.lang.IllegalStateException: Fatal Exception thrown on Scheduler.Worker thread. at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:62) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: rx.exceptions.OnErrorFailedException: Error occurred when trying to propagate error to Observer.onError at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201) at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111) at rx.internal.operators.OperatorSubscribeOn$1$1$1.onError(OperatorSubscribeOn.java:71) at rx.internal.operators.OperatorMerge$MergeSubscriber.innerError(OperatorMerge.java:457) at rx.internal.operators.OperatorMerge$MergeSubscriber.onError(OperatorMerge.java:432) at rx.internal.operators.OperatorMapPair$2.onError(OperatorMapPair.java:74) at rx.android.app.OperatorConditionalBinding$1.onError(OperatorConditionalBinding.java:69) at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:183) at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:159) at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)            at android.os.Handler.handleCallback(Handler.java:739)            at android.os.Handler.dispatchMessage(Handler.java:95)            at android.os.Looper.loop(Looper.java:135)            at android.app.ActivityThread.main(ActivityThread.java:5221)            at java.lang.reflect.Method.invoke(Native Method)            at java.lang.reflect.Method.invoke(Method.java:372)            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: rx.exceptions.CompositeException: 2 exceptions occurred.            at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:201)            at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:111)            at rx.internal.operators.OperatorSubscribeOn$1$1$1.onError(OperatorSubscribeOn.java:71)            at rx.internal.operators.OperatorMerge$MergeSubscriber.innerError(OperatorMerge.java:457)            at rx.internal.operators.OperatorMerge$MergeSubscriber.onError(OperatorMerge.java:432)            at rx.internal.operators.OperatorMapPair$2.onError(OperatorMapPair.java:74)            at rx.android.app.OperatorConditionalBinding$1.onError(OperatorConditionalBinding.java:69)            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:183)            at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:159)            at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)            at android.os.Handler.handleCallback(Handler.java:739)            at android.os.Handler.dispatchMessage(Handler.java:95)            at android.os.Looper.loop(Looper.java:135)            at android.app.ActivityThread.main(ActivityThread.java:5221)            at java.lang.reflect.Method.invoke(Native Method)            at java.lang.reflect.Method.invoke(Method.java:372)            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: rx.exceptions.CompositeException$CompositeExceptionCausalChain: Chain of Causes for CompositeException In Order Received => at com.flurry.sdk.bx.uncaughtException(SourceFile:325) at com.flurry.sdk.eq.a(SourceFile:90) at com.flurry.sdk.eq.a(SourceFile:19) at com.flurry.sdk.eq$a.uncaughtException(SourceFile:106) at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693) at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690) at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:66)            at android.os.Handler.handleCallback(Handler.java:739)            at android.os.Handler.dispatchMessage(Handler.java:95)            at android.os.Looper.loop(Looper.java:135)            at android.app.ActivityThread.main(ActivityThread.java:5221)            at java.lang.reflect.Method.invoke(Native Method)            at java.lang.reflect.Method.invoke(Method.java:372)            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) Caused by: retrofit.RetrofitError: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 11 path $[0].name at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:383) at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220) at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265) at retrofit.RxSupport$2.run(RxSupport.java:55) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at retrofit.Platform$Android$2$1.run(Platform.java:142) at java.lang.Thread.run(Thread.java:818) Caused by: retrofit.converter.ConversionException: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 11 path $[0].name at retrofit.converter.GsonConverter.fromBody(GsonConverter.java:67) at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:367)            at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)            at retrofit.RestAdapter$RestHandler$1.invoke(RestAdapter.java:265)            at retrofit.RxSupport$2.run(RxSupport.java:55)            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)            at java.util.concurrent.FutureTask.run(FutureTask.java:237)            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)            at retrofit.Platform$Android$2$1.run(Platform.java:142)            at java.lang.Thread.run(Thread.java:818) Caused by: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 11 path $[0].name at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:200) at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81) at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFac 
  • As far as I remember Rx, if an exception happens inside, then further enumeration stops. That is, after onError is triggered, nothing else happens; when you try to add a new event, the error status remains. You need to recreate Observable (or suppress the error somehow else). Maybe you have this problem? - VladD
  • @VladD yes, I thought so too. But the first time it works. And the JsonSyntaxException error is caught. In the showError () method, the "repeat" button is simply displayed, and by clicking on it, the doRequest () method is called again andreich

2 answers 2

In general, the problem is solved. First, I updated rxJava to the latest version at the current moment

 compile 'io.reactivex:rxjava:1.0.11' 

after that, the logs became more meaningful, and there, yes, it became clear that the non-catchable exception was thrown. Further added a call for an error and that's it. The oddity is that before writing a post, I tried to do so, but it did not work.

 .onErrorResumeNext(new Func1<Throwable, Observable<? extends Boolean>>() { @Override public Observable<? extends Boolean> call(Throwable throwable) { return Observable.create(new Observable.OnSubscribe<Boolean>() { @Override public void call(Subscriber<? super Boolean> subscriber) { subscriber.onNext(false); subscriber.onCompleted(); } }); } }) 

    And an error can occur in a network request, but an error handler:

     Observable.OnSubscribe<List<Object>>() { @Override public void call(Subscriber<? super List<Object>> subscriber) { //тут происходят какие-то сетевые запросы //если все плохо, то кидается исключение //это исключение и не отлавливается при повторном выполнении этого кода subscriber.onNext(new ArrayList<>()); subscriber.onCompleted(); } })) 

    Where is the subscriber.onError (Throwable e) code?

    • He's not needed. The thrown exception should come in Action1 <Throwable> () which is initialized in the subscribe method - andreich
    • I recently started learning to study rxJava, but it seems to me (most likely) that there is not a matching thread (Error to try to propagate error to Observer.onError). The error goes to another thread that cannot process and return it. AppObservable.bindFragment this thing does observeOn (AndroidSchedulers.mainThread ()). You can try to add before subscribe, subscribeOn (Schedulers.io ()). I received such an error exactly when the subscription and the execution were in different streams. - retor