本文整理汇总了Java中io.reactivex.exceptions.Exceptions类的典型用法代码示例。如果您正苦于以下问题:Java Exceptions类的具体用法?Java Exceptions怎么用?Java Exceptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Exceptions类属于io.reactivex.exceptions包,在下文中一共展示了Exceptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMetadata
import io.reactivex.exceptions.Exceptions; //导入依赖的package包/类
@Override
public Observable<Metadata> getMetadata() {
return Observable.defer(() -> {
final File metadata = new File(directory, "config.json");
try {
if (metadata.exists()) {
final String raw = FileUtils.readFileToString(metadata, "UTF-8");
final Metadata result = new Metadata.Builder().setTileJson(raw).build();
return Observable.just(result);
}
} catch (final IOException ex) {
throw Exceptions.propagate(ex);
}
return Observable.empty();
});
}
示例2: resultThrowingInOnSuccessDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的package包/类
@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);
}
示例3: get
import io.reactivex.exceptions.Exceptions; //导入依赖的package包/类
private Observable<Entry> get(SelectBuilder builder) {
if (isError) {
return Observable.empty();
} else {
return builder.get(new ResultSetMapper<Entry>() {
@Override
public Entry apply(@Nonnull ResultSet rs) throws SQLException {
byte[] uncompressed;
try {
final byte[] compressedTileData = rs.getBytes("tile_data");
uncompressed = CompressUtil.getUncompressedFromGzip(compressedTileData);
} catch (final IOException ex) {
throw Exceptions.propagate(ex);
}
return new Entry(rs.getInt("zoom_level"), rs.getInt("tile_column"),
flipY(rs.getInt("tile_row"), rs.getInt("zoom_level")), uncompressed);
}
}).toObservable();
}
}
示例4: onComplete
import io.reactivex.exceptions.Exceptions; //导入依赖的package包/类
@Override
public void onComplete(@NonNull Task<Void> task) {
if (isDisposed()) return;
if (!task.isSuccessful()) {
Exception exception = task.getException();
if (terminated) {
RxJavaPlugins.onError(exception);
} else {
try {
terminated = true;
observer.onError(exception);
} catch (Throwable t) {
Exceptions.throwIfFatal(t);
RxJavaPlugins.onError(new CompositeException(task.getException(), t));
}
}
}
}
示例5: onResponse
import io.reactivex.exceptions.Exceptions; //导入依赖的package包/类
@Override public void onResponse(Call<T> call, Response<T> response) {
if (call.isCanceled()) return;
try {
observer.onNext(response);
if (!call.isCanceled()) {
terminated = true;
observer.onComplete();
}
} catch (Throwable t) {
if (terminated) {
RxJavaPlugins.onError(t);
} else if (!call.isCanceled()) {
try {
observer.onError(t);
} catch (Throwable inner) {
Exceptions.throwIfFatal(inner);
RxJavaPlugins.onError(new CompositeException(t, inner));
}
}
}
}
示例6: bodyThrowingInOnSuccessDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的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);
}
}
});
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);
}
示例7: throwingInOnCompleteDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的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);
}
示例8: bodyThrowingInOnCompleteDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的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);
}
示例9: responseThrowingInOnCompleteDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的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);
}
示例10: resultThrowingInOnCompletedDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的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);
}
示例11: throwingInOnCompleteDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的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);
}
示例12: bodyThrowingInOnSuccessDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的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);
}
示例13: responseThrowingInOnSuccessDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的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);
}
示例14: resultThrowingInOnSuccessDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的package包/类
@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);
}
示例15: bodyThrowingInOnCompleteDeliveredToPlugin
import io.reactivex.exceptions.Exceptions; //导入依赖的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);
}