本文整理汇总了Java中io.reactivex.plugins.RxJavaPlugins.setErrorHandler方法的典型用法代码示例。如果您正苦于以下问题:Java RxJavaPlugins.setErrorHandler方法的具体用法?Java RxJavaPlugins.setErrorHandler怎么用?Java RxJavaPlugins.setErrorHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.plugins.RxJavaPlugins
的用法示例。
在下文中一共展示了RxJavaPlugins.setErrorHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: throwingInOnCompleteDeliveredToPlugin
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@Test public void throwingInOnCompleteDeliveredToPlugin() throws InterruptedException {
server.enqueue(new MockResponse());
final CountDownLatch latch = new CountDownLatch(1);
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!
}
latch.countDown();
}
});
TestObserver<Void> observer = new TestObserver<>();
final RuntimeException e = new RuntimeException();
service.completable().subscribe(new ForwardingCompletableObserver(observer) {
@Override public void onComplete() {
throw e;
}
});
latch.await(1, SECONDS);
assertThat(errorRef.get()).isSameAs(e);
}
示例2: responseThrowingInOnCompleteDeliveredToPlugin
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@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);
}
示例3: throwingInOnCompleteDeliveredToPlugin
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@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);
}
示例4: bodyThrowingInOnCompleteDeliveredToPlugin
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@Test public void bodyThrowingInOnCompleteDeliveredToPlugin() {
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<String> observer = subscriberRule.create();
final RuntimeException e = new RuntimeException();
service.body().subscribe(new ForwardingObserver<String>(observer) {
@Override public void onComplete() {
throw e;
}
});
observer.assertAnyValue();
assertThat(throwableRef.get()).isSameAs(e);
}
示例5: bodyThrowingInOnSuccessDeliveredToPlugin
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@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);
}
示例6: resultThrowingInOnCompletedDeliveredToPlugin
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@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);
}
示例7: bodyThrowingInOnCompleteDeliveredToPlugin
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@Test public void bodyThrowingInOnCompleteDeliveredToPlugin() {
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<String> subscriber = subscriberRule.create();
final RuntimeException e = new RuntimeException();
service.body().subscribe(new ForwardingSubscriber<String>(subscriber) {
@Override public void onComplete() {
throw e;
}
});
subscriber.assertAnyValue();
assertThat(throwableRef.get()).isSameAs(e);
}
示例8: responseThrowingInOnSuccessDeliveredToPlugin
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@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);
}
示例9: resultThrowingInOnCompletedDeliveredToPlugin
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@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);
}
示例10: responseThrowingInOnSuccessDeliveredToPlugin
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@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);
}
示例11: apply
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
// we have to cache the current handler first before running the test
Thread.UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) ->
throwableRef.set(throwable)
);
Consumer<? super Throwable> oldRxJavaHandler = RxJavaPlugins.getErrorHandler();
RxJavaPlugins.setErrorHandler(Errors::onError);
try {
base.evaluate();
} finally {
// and restore cached handlers here
Thread.setDefaultUncaughtExceptionHandler(oldHandler);
RxJavaPlugins.setErrorHandler(oldRxJavaHandler);
verify();
// Some other exception might have happened on base.evaluate(), but if it is so,
// it might be a side consequence of uncaught exception discovered by this
// rule. For this reason we are are verifying in finally, if this rule will
// report failure, then an exception thrown in base.evaluate() will be suppressed.
// It will be reported eventually once the original problem with expected or
// unexpected uncaught exception is resolved.
}
}
};
}
示例12: initLogging
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
/**
* Performs initialization of the app logging.
*/
protected void initLogging() {
Timber.plant(new Timber.DebugTree() {
protected String createStackElementTag(StackTraceElement element) {
return super.createStackElementTag(element) + " : " + element.getLineNumber();
}
});
RxJavaPlugins.setErrorHandler(Timber::e);
}
示例13: onCreate
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
context = this;
initializeTimber();
RxJavaPlugins.setErrorHandler(throwable -> Timber.e(throwable.toString()));
// Configure default configuration for Realm
Realm.init(this);
RealmConfiguration realmConfig = new RealmConfiguration.Builder().build();
Realm.setDefaultConfiguration(realmConfig);
}
示例14: onCreate
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RxJavaPlugins.setErrorHandler(ErrorHandler.get());
ButterKnife.bind(this);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
stockDataAdapter = new StockDataAdapter();
recyclerView.setAdapter(stockDataAdapter);
Observable.just("Please use this app responsibly!")
.subscribe(s -> helloText.setText(s));
YahooService yahooService = new RetrofitYahooServiceFactory().create();
String query = "select * from yahoo.finance.quote where symbol in ('YHOO','AAPL','GOOG','MSFT')";
String env = "store://datatables.org/alltableswithkeys";
Observable.interval(0, 5, TimeUnit.SECONDS)
.flatMap(
i -> Observable.<YahooStockResult>error(new RuntimeException("Crash"))
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.doOnError(error -> {
log("doOnError", "error");
Toast.makeText(this, "We couldn't reach internet - falling back to local data",
Toast.LENGTH_SHORT)
.show();
})
.observeOn(Schedulers.io())
.map(r -> r.getQuery().getResults().getQuote())
.flatMap(Observable::fromIterable)
.map(StockUpdate::create)
.doOnNext(this::saveStockUpdate)
.onExceptionResumeNext(
v2(StorIOFactory.get(this)
.get()
.listOfObjects(StockUpdate.class)
.withQuery(Query.builder()
.table(StockUpdateTable.TABLE)
.orderBy("date DESC")
.limit(50)
.build())
.prepare()
.asRxObservable())
.take(1)
.flatMap(Observable::fromIterable)
)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(stockUpdate -> {
Log.d("APP", "New update " + stockUpdate.getStockSymbol());
noDataAvailableView.setVisibility(View.GONE);
stockDataAdapter.add(stockUpdate);
}, error -> {
if (stockDataAdapter.getItemCount() == 0) {
noDataAvailableView.setVisibility(View.VISIBLE);
}
});
// demo10();
}
示例15: trackPluginErrors
import io.reactivex.plugins.RxJavaPlugins; //导入方法依赖的package包/类
public static List<Throwable> trackPluginErrors() {
final List<Throwable> list = Collections.synchronizedList(new ArrayList<Throwable>());
RxJavaPlugins.setErrorHandler(list::add);
return list;
}