本文整理了Java中java.lang.Throwable.<init>()
方法的一些代码示例,展示了Throwable.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Throwable.<init>()
方法的具体详情如下:
包路径:java.lang.Throwable
类名称:Throwable
方法名:<init>
[英]Constructs a new Throwable that includes the current stack trace.
[中]
代码示例来源:origin: square/okhttp
/**
* Returns an object that holds a stack trace created at the moment this method is executed. This
* should be used specifically for {@link java.io.Closeable} objects and in conjunction with
* {@link #logCloseableLeak(String, Object)}.
*/
public Object getStackTraceForCloseable(String closer) {
if (logger.isLoggable(Level.FINE)) {
return new Throwable(closer); // These are expensive to allocate.
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(Method method, Class<?> targetClass, Object... args) {
this.evaluations++;
for (StackTraceElement element : new Throwable().getStackTrace()) {
if (element.getClassName().equals(this.clazz.getName()) &&
(this.methodName == null || element.getMethodName().equals(this.methodName))) {
return true;
}
}
return false;
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscribed.set(true);
subscriber.onSubscribe(bs);
subscriber.onError(new Throwable("test failed"));
}
});
代码示例来源:origin: google/guava
public void testTrustedGetFailure_Failed() {
SettableFuture<String> future = SettableFuture.create();
Throwable failure = new Throwable();
future.setException(failure);
assertThat(future.tryInternalFastPathGetFailure()).isEqualTo(failure);
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(Observer<? super String> observer) {
subscribed.set(true);
observer.onSubscribe(bs);
observer.onError(new Throwable("test failed"));
}
});
代码示例来源:origin: google/guava
public void testAllAsList_immediateFailure() throws Exception {
Throwable exception = new Throwable("failed");
ListenableFuture<String> future1 = immediateFailedFuture(exception);
ListenableFuture<String> future2 = immediateFuture("results");
ListenableFuture<List<String>> compound = allAsList(ImmutableList.of(future1, future2));
try {
getDone(compound);
fail();
} catch (ExecutionException expected) {
assertSame(exception, expected.getCause());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onNext("one");
subscriber.onError(new Throwable("test failed"));
}
});
代码示例来源:origin: google/guava
public void testAllAsList_singleFailure() throws Exception {
Throwable exception = new Throwable("failed");
ListenableFuture<String> future = immediateFailedFuture(exception);
ListenableFuture<List<String>> compound = allAsList(ImmutableList.of(future));
try {
getDone(compound);
fail();
} catch (ExecutionException expected) {
assertSame(exception, expected.getCause());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testDematerialize2() {
Throwable exception = new Throwable("test");
Observable<Integer> o = Observable.error(exception);
Observable<Integer> dematerialize = o.materialize().dematerialize();
Observer<Integer> observer = TestHelper.mockObserver();
dematerialize.subscribe(observer);
verify(observer, times(1)).onError(exception);
verify(observer, times(0)).onComplete();
verify(observer, times(0)).onNext(any(Integer.class));
}
代码示例来源:origin: google/guava
public void testGetFailure_Failed() {
AbstractFuture<String> future = new AbstractFuture<String>() {};
final Throwable failure = new Throwable();
future.setException(failure);
assertThat(future.tryInternalFastPathGetFailure()).isNull();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testDematerialize2() {
Throwable exception = new Throwable("test");
Flowable<Integer> flowable = Flowable.error(exception);
Flowable<Integer> dematerialize = flowable.materialize().dematerialize();
Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
dematerialize.subscribe(subscriber);
verify(subscriber, times(1)).onError(exception);
verify(subscriber, times(0)).onComplete();
verify(subscriber, times(0)).onNext(any(Integer.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
subscriber.onNext("one");
subscriber.onError(new Throwable("injected failure"));
subscriber.onNext("two");
subscriber.onNext("three");
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(Observer<? super String> observer) {
observer.onSubscribe(Disposables.empty());
observer.onNext("one");
observer.onError(new Throwable("test failed"));
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(Observer<? super String> observer) {
observer.onSubscribe(Disposables.empty());
observer.onNext("one");
observer.onError(new Throwable("test failed"));
}
});
代码示例来源:origin: spring-projects/spring-framework
@Test
public void isCheckedException() {
assertTrue(ObjectUtils.isCheckedException(new Exception()));
assertTrue(ObjectUtils.isCheckedException(new SQLException()));
assertFalse(ObjectUtils.isCheckedException(new RuntimeException()));
assertFalse(ObjectUtils.isCheckedException(new IllegalArgumentException("")));
// Any Throwable other than RuntimeException and Error
// has to be considered checked according to the JLS.
assertTrue(ObjectUtils.isCheckedException(new Throwable()));
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void subscribe(Observer<? super String> observer) {
observer.onSubscribe(Disposables.empty());
observer.onNext("one");
observer.onError(new Throwable("injected failure"));
observer.onNext("two");
observer.onNext("three");
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_NormalPath() {
Throwable exception = new Throwable();
Flowable<Integer> source = Flowable.mergeDelayError(Flowable.range(1, 2), Flowable.<Integer>error(exception));
TestSubscriber<Integer> subscriber = new TestSubscriber<Integer>(0L);
source.subscribe(subscriber);
subscriber.request(3); // 1, 2, <error>
subscriber.assertValues(1, 2);
subscriber.assertTerminated();
assertEquals(asList(exception), subscriber.errors());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_FastPath() {
Throwable exception = new Throwable();
Flowable<Integer> source = Flowable.mergeDelayError(Flowable.just(1), Flowable.<Integer>error(exception));
TestSubscriber<Integer> subscriber = new TestSubscriber<Integer>(0L);
source.subscribe(subscriber);
subscriber.request(2); // 1, <error>
subscriber.assertValue(1);
subscriber.assertTerminated();
assertEquals(asList(exception), subscriber.errors());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void shouldNotReceivedDelayedErrorWhileThereAreStillScalarSynchronousEmissionsInTheQueue() {
Throwable exception = new Throwable();
Flowable<Integer> source = Flowable.mergeDelayError(Flowable.just(1), Flowable.just(2), Flowable.<Integer>error(exception));
TestSubscriber<Integer> subscriber = new TestSubscriber<Integer>(0L);
subscriber.request(1);
source.subscribe(subscriber);
subscriber.assertValue(1);
assertEquals(Collections.<Throwable>emptyList(), subscriber.errors());
subscriber.request(1);
subscriber.assertValues(1, 2);
assertEquals(asList(exception), subscriber.errors());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void shouldNotReceivedDelayedErrorWhileThereAreStillNormalEmissionsInTheQueue() {
Throwable exception = new Throwable();
Flowable<Integer> source = Flowable.mergeDelayError(Flowable.range(1, 2), Flowable.range(3, 2), Flowable.<Integer>error(exception));
TestSubscriber<Integer> subscriber = new TestSubscriber<Integer>(0L);
subscriber.request(3);
source.subscribe(subscriber);
subscriber.assertValues(1, 2, 3);
assertEquals(Collections.<Throwable>emptyList(), subscriber.errors());
subscriber.request(2);
subscriber.assertValues(1, 2, 3, 4);
assertEquals(asList(exception), subscriber.errors());
}
内容来源于网络,如有侵权,请联系作者删除!