io.reactivex.FlowableSubscriber#io.reactivex.exceptions.Exceptions源码实例Demo

下面列出了io.reactivex.FlowableSubscriber#io.reactivex.exceptions.Exceptions 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sqlitemagic   文件: OperatorRunSingleItemQuery.java
@Override
public void onNext(Query<T> query) {
  try {
    // null cursor here is valid
    final Cursor cursor = query.rawQuery(true);
    final T item = query.map(cursor);
    if (!isDisposed()) {
      if (item != null) {
        downstream.onNext(item);
      } else if (defaultValue != null) {
        downstream.onNext(defaultValue);
      }
    }
  } catch (Throwable e) {
    Exceptions.throwIfFatal(e);
    onError(e);
  }
}
 
源代码2 项目: RxEasyHttp   文件: RxCache.java
@Override
public void subscribe(@NonNull ObservableEmitter<T> subscriber) throws Exception {
    try {
        T data = execute();
        if (!subscriber.isDisposed()) {
            subscriber.onNext(data);
        }
    } catch (Throwable e) {
        HttpLog.e(e.getMessage());
        if (!subscriber.isDisposed()) {
            subscriber.onError(e);
        }
        Exceptions.throwIfFatal(e);
        //RxJavaPlugins.onError(e);
        return;
    }

    if (!subscriber.isDisposed()) {
        subscriber.onComplete();
    }
}
 
源代码3 项目: apollo-android   文件: Rx2Apollo.java
/**
 * Converts an {@link ApolloQueryWatcher} to an asynchronous Observable.
 *
 * @param watcher the ApolloQueryWatcher to convert.
 * @param <T>     the value type
 * @return the converted Observable
 * @throws NullPointerException if watcher == null
 */
@NotNull
@CheckReturnValue
public static <T> Observable<Response<T>> from(@NotNull final ApolloQueryWatcher<T> watcher) {
  checkNotNull(watcher, "watcher == null");
  return Observable.create(new ObservableOnSubscribe<Response<T>>() {
    @Override public void subscribe(final ObservableEmitter<Response<T>> emitter) throws Exception {
      cancelOnObservableDisposed(emitter, watcher);

      watcher.enqueueAndWatch(new ApolloCall.Callback<T>() {
        @Override public void onResponse(@NotNull Response<T> response) {
          if (!emitter.isDisposed()) {
            emitter.onNext(response);
          }
        }

        @Override public void onFailure(@NotNull ApolloException e) {
          Exceptions.throwIfFatal(e);
          if (!emitter.isDisposed()) {
            emitter.onError(e);
          }
        }
      });
    }
  });
}
 
源代码4 项目: bitshares_wallet   文件: SendFragment.java
private void processGetTransferToId(final String strAccount, final TextView textViewTo) {
    Flowable.just(strAccount)
            .subscribeOn(Schedulers.io())
            .map(accountName -> {
                account_object accountObject = BitsharesWalletWraper.getInstance().get_account_object(accountName);
                if (accountObject == null) {
                    throw new ErrorCodeException(ErrorCode.ERROR_NO_ACCOUNT_OBJECT, "it can't find the account");
                }

                return accountObject;
            }).observeOn(AndroidSchedulers.mainThread())
            .subscribe(accountObject -> {
                if (getActivity() != null && getActivity().isFinishing() == false) {
                    textViewTo.setText("#" + accountObject.id.get_instance());
                }
            }, throwable -> {
                if (throwable instanceof NetworkStatusException || throwable instanceof ErrorCodeException) {
                    if (getActivity() != null && getActivity().isFinishing() == false) {
                        textViewTo.setText("#none");
                    }
                } else {
                    throw Exceptions.propagate(throwable);
                }
            });
}
 
源代码5 项目: retrocache   文件: MaybeThrowingTest.java
@Test
public void bodyThrowingInOnSuccessDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });

    RecordingMaybeObserver<String> observer = subscriberRule.create();
    final RuntimeException e = new RuntimeException();
    service.body().subscribe(new ForwardingObserver<String>(observer) {
        @Override
        public void onSuccess(String value) {
            throw e;
        }
    });

    assertThat(throwableRef.get()).isSameAs(e);
}
 
源代码6 项目: retrocache   文件: MaybeThrowingTest.java
@Test
public void responseThrowingInOnSuccessDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });

    RecordingMaybeObserver<Response<String>> observer = subscriberRule.create();
    final RuntimeException e = new RuntimeException();
    service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
        @Override
        public void onSuccess(Response<String> value) {
            throw e;
        }
    });

    assertThat(throwableRef.get()).isSameAs(e);
}
 
源代码7 项目: retrocache   文件: MaybeThrowingTest.java
@Test
public void resultThrowingInOnSuccessDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });

    RecordingMaybeObserver<Result<String>> observer = subscriberRule.create();
    final RuntimeException e = new RuntimeException();
    service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
        @Override
        public void onSuccess(Result<String> value) {
            throw e;
        }
    });

    assertThat(throwableRef.get()).isSameAs(e);
}
 
源代码8 项目: retrocache   文件: CompletableThrowingTest.java
@Test
public void throwingInOnCompleteDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> errorRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!errorRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
            }
        }
    });

    RecordingCompletableObserver observer = observerRule.create();
    final RuntimeException e = new RuntimeException();
    service.completable().subscribe(new ForwardingCompletableObserver(observer) {
        @Override
        public void onComplete() {
            throw e;
        }
    });

    assertThat(errorRef.get()).isSameAs(e);
}
 
源代码9 项目: retrocache   文件: ObservableThrowingTest.java
@Test
public void responseThrowingInOnCompleteDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });

    RecordingObserver<Response<String>> observer = subscriberRule.create();
    final RuntimeException e = new RuntimeException();
    service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
        @Override
        public void onComplete() {
            throw e;
        }
    });

    observer.assertAnyValue();
    assertThat(throwableRef.get()).isSameAs(e);
}
 
源代码10 项目: retrocache   文件: ObservableThrowingTest.java
@Test
public void resultThrowingInOnCompletedDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });

    RecordingObserver<Result<String>> observer = subscriberRule.create();
    final RuntimeException e = new RuntimeException();
    service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
        @Override
        public void onComplete() {
            throw e;
        }
    });

    observer.assertAnyValue();
    assertThat(throwableRef.get()).isSameAs(e);
}
 
源代码11 项目: retrocache   文件: SingleThrowingTest.java
@Test
public void bodyThrowingInOnSuccessDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });

    RecordingSingleObserver<String> observer = subscriberRule.create();
    final RuntimeException e = new RuntimeException();
    service.body().subscribe(new ForwardingObserver<String>(observer) {
        @Override
        public void onSuccess(String value) {
            throw e;
        }
    });

    assertThat(throwableRef.get()).isSameAs(e);
}
 
源代码12 项目: retrocache   文件: SingleThrowingTest.java
@Test
public void responseThrowingInOnSuccessDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });

    RecordingSingleObserver<Response<String>> observer = subscriberRule.create();
    final RuntimeException e = new RuntimeException();
    service.response().subscribe(new ForwardingObserver<Response<String>>(observer) {
        @Override
        public void onSuccess(Response<String> value) {
            throw e;
        }
    });

    assertThat(throwableRef.get()).isSameAs(e);
}
 
源代码13 项目: retrocache   文件: SingleThrowingTest.java
@Test
public void resultThrowingInOnSuccessDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });

    RecordingSingleObserver<Result<String>> observer = subscriberRule.create();
    final RuntimeException e = new RuntimeException();
    service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
        @Override
        public void onSuccess(Result<String> value) {
            throw e;
        }
    });

    assertThat(throwableRef.get()).isSameAs(e);
}
 
源代码14 项目: retrocache   文件: FlowableThrowingTest.java
@Test
public void responseThrowingInOnCompleteDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });

    RecordingSubscriber<Response<String>> subscriber = subscriberRule.create();
    final RuntimeException e = new RuntimeException();
    service.response().subscribe(new ForwardingSubscriber<Response<String>>(subscriber) {
        @Override
        public void onComplete() {
            throw e;
        }
    });

    subscriber.assertAnyValue();
    assertThat(throwableRef.get()).isSameAs(e);
}
 
源代码15 项目: retrocache   文件: FlowableThrowingTest.java
@Test
public void resultThrowingInOnCompletedDeliveredToPlugin() {
    server.enqueue(new MockResponse());

    final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
    RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
        @Override
        public void accept(Throwable throwable) throws Exception {
            if (!throwableRef.compareAndSet(null, throwable)) {
                throw Exceptions.propagate(throwable);
            }
        }
    });

    RecordingSubscriber<Result<String>> subscriber = subscriberRule.create();
    final RuntimeException e = new RuntimeException();
    service.result().subscribe(new ForwardingSubscriber<Result<String>>(subscriber) {
        @Override
        public void onComplete() {
            throw e;
        }
    });

    subscriber.assertAnyValue();
    assertThat(throwableRef.get()).isSameAs(e);
}
 
源代码16 项目: rxjava2-extras   文件: FlowableInsertTimeout.java
@Override
public void onNext(final T t) {
    if (finished) {
        return;
    }
    queue.offer(t);
    final long waitTime;
    try {
        waitTime = timeout.apply(t);
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        // we cancel upstream ourselves because the
        // error did not originate from source
        upstream.cancel();
        onError(e);
        return;
    }
    TimeoutAction<T> action = new TimeoutAction<T>(this, t);
    Disposable d = worker.schedule(action, waitTime, unit);
    DisposableHelper.set(scheduled, d);
    drain();
}
 
源代码17 项目: rxjava2-extras   文件: FlowableDoOnEmpty.java
@Override
public void onComplete() {
    if (done) {
        return;
    }
    if (empty) {
        try {
            onEmpty.run();
        } catch (Throwable e) {
            Exceptions.throwIfFatal(e);
            onError(e);
            return;
        }
    }
    done = true;
    child.onComplete();
}
 
源代码18 项目: rxjava2-extras   文件: FlowableMapLast.java
@Override
public void onComplete() {
    if (done) {
        return;
    }
    if (value != EMPTY) {
        T value2;
        try {
            value2 = function.apply(value);
        } catch (Throwable e) {
            Exceptions.throwIfFatal(e);
            parent.cancel();
            onError(e);
            return;
        }
        actual.onNext(value2);
    }
    done = true;
    actual.onComplete();
}
 
@Override
protected void subscribeActual(Subscriber<? super T> child) {

    Flowable<T> f;
    try {
        f = transform.apply(source);
    } catch (Exception e) {
        Exceptions.throwIfFatal(e);
        child.onSubscribe(SubscriptionHelper.CANCELLED);
        child.onError(e);
        return;
    }
    AtomicReference<Chain<T>> chainRef = new AtomicReference<Chain<T>>();
    DestinationSerializedSubject<T> destination = new DestinationSerializedSubject<T>(child,
            chainRef);
    Chain<T> chain = new Chain<T>(transform, destination, maxIterations, maxChained, tester);
    chainRef.set(chain);
    // destination is not initially subscribed to the chain but will be when
    // tester function result completes
    destination.subscribe(child);
    ChainedReplaySubject<T> sub = ChainedReplaySubject.create(destination, chain, tester);
    chain.initialize(sub);
    f.onTerminateDetach() //
            .subscribe(sub);
}
 
源代码20 项目: rxjava2-extras   文件: FlowableInsertMaybe.java
@Override
public void onNext(T t) {
    if (finished) {
        return;
    }
    queue.offer(t);
    Maybe<? extends T> maybe;
    try {
        maybe = valueToInsert.apply(t);
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        // we cancel upstream ourselves because the
        // error did not originate from source
        upstream.cancel();
        onError(e);
        return;
    }
    ValueToInsertObserver<T> o = new ValueToInsertObserver<T>(this);
    if (DisposableHelper.set(valueToInsertObserver, o)) {
        // note that at this point we have to cover o being disposed
        // from another thread so the Observer class needs
        // to handle dispose being called before/during onSubscribe
        maybe.subscribe(o);
    }
    drain();
}
 
源代码21 项目: rxjava2-extras   文件: FlowableStateMachine.java
@Override
public void onNext(In t) {
    if (done) {
        return;
    }
    if (!createdState()) {
        return;
    }
    if (--count == 0) {
        requestsArrived = true;
        count = requestBatchSize;
    }
    try {
        drainCalled = false;
        state = ObjectHelper.requireNonNull(transition.apply(state, t, this),
                "intermediate state cannot be null");
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        onError(e);
        return;
    }
    if (!drainCalled) {
        drain();
    }
}
 
源代码22 项目: rxjava2-extras   文件: FlowableStateMachine.java
private boolean createdState() {
    if (state == null) {
        try {
            state = ObjectHelper.requireNonNull(initialState.call(),
                    "initial state cannot be null");
            return true;
        } catch (Throwable e) {
            Exceptions.throwIfFatal(e);
            done = true;
            onError_(e);
            return false;
        }
    } else {
        return true;
    }
}
 
源代码23 项目: rxjava2-extras   文件: FlowableStateMachine.java
@Override
public void onComplete() {
    if (done) {
        return;
    }
    if (!createdState()) {
        return;
    }
    try {
        if (completionAction != null) {
            completionAction.accept(state, this);
        } else {
            onComplete_();
        }
        done = true;
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        onError(e);
        return;
    }
}
 
源代码24 项目: iroha-java   文件: IrohaAPI.java
/**
 * Close GRPC connection.
 */
public void terminate() {
  if (!channel.isTerminated()) {
    channel.shutdownNow();
    boolean terminated = false;
    do {
      try {
        terminated = channel.awaitTermination(30, TimeUnit.SECONDS);
      } catch (InterruptedException e) {
        Exceptions.propagate(e);
      }
    } while (!terminated);
  }
}
 
@Override
public void onError(Throwable t) {
  try {
    this.onError.accept(t);
  } catch (Exception e) {
    Exceptions.propagate(e);
  }
}
 
源代码26 项目: rxjava-RxLife   文件: LifeSubscriber.java
@Override
public void onSubscribe(Subscription s) {
    if (SubscriptionHelper.setOnce(this, s)) {
        try {
            addObserver();
            downstream.onSubscribe(s);
        } catch (Throwable ex) {
            Exceptions.throwIfFatal(ex);
            s.cancel();
            onError(ex);
        }
    }
}
 
源代码27 项目: rxjava-RxLife   文件: LifeSubscriber.java
@Override
public void onNext(T t) {
    if (isDisposed()) return;
    try {
        downstream.onNext(t);
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        get().cancel();
        onError(e);
    }
}
 
源代码28 项目: rxjava-RxLife   文件: LifeSubscriber.java
@Override
public void onError(Throwable t) {
    if (isDisposed()) {
        RxJavaPlugins.onError(t);
        return;
    }
    lazySet(SubscriptionHelper.CANCELLED);
    try {
        removeObserver();
        downstream.onError(t);
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        RxJavaPlugins.onError(new CompositeException(t, e));
    }
}
 
源代码29 项目: rxjava-RxLife   文件: LifeSubscriber.java
@Override
public void onComplete() {
    if (isDisposed()) return;
    lazySet(SubscriptionHelper.CANCELLED);
    try {
        removeObserver();
        downstream.onComplete();
    } catch (Throwable e) {
        Exceptions.throwIfFatal(e);
        RxJavaPlugins.onError(e);
    }
}
 
源代码30 项目: rxjava-RxLife   文件: LifeObserver.java
@Override
public void onSubscribe(Disposable d) {
    if (DisposableHelper.setOnce(this, d)) {
        try {
            addObserver();
            downstream.onSubscribe(d);
        } catch (Throwable ex) {
            Exceptions.throwIfFatal(ex);
            d.dispose();
            onError(ex);
        }
    }
}