本文整理了Java中java.lang.Throwable.getMessage()
方法的一些代码示例,展示了Throwable.getMessage()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Throwable.getMessage()
方法的具体详情如下:
包路径:java.lang.Throwable
类名称:Throwable
方法名:getMessage
[英]Returns the detail message which was provided when this Throwable was created. Returns null if no message was provided at creation time.
[中]返回创建此可丢弃文件时提供的详细信息。如果在创建时未提供任何消息,则返回null。
代码示例来源:origin: google/guava
@Override
public final void tearDown() {
try {
sloppyTearDown();
} catch (Throwable t) {
logger.log(Level.INFO, "exception thrown during tearDown: " + t.getMessage(), t);
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public boolean test(Throwable t) {
return t.getMessage() != null && t.getMessage().contains("Forced");
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public boolean test(Throwable t) throws Exception {
return t.getMessage() != null && t.getMessage().contains("Forced");
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public void onError(Throwable e) {
System.out.println("error: " + e.getMessage());
e.printStackTrace();
}
代码示例来源:origin: google/guava
private static void assertErrorMessage(Throwable e, String message) {
// TODO(kevinb): use a Truth assertion here
if (!e.getMessage().contains(message)) {
fail("expected <" + e.getMessage() + "> to contain <" + message + ">");
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void onError(Throwable e) {
threadsRunning.incrementAndGet();
System.out.println(">>> Busyobserver received onError: " + e.getMessage());
onError = true;
int concurrentThreads = threadsRunning.get();
int maxThreads = maxConcurrentThreads.get();
if (concurrentThreads > maxThreads) {
maxConcurrentThreads.compareAndSet(maxThreads, concurrentThreads);
}
threadsRunning.decrementAndGet();
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void onError(Throwable e) {
threadsRunning.incrementAndGet();
System.out.println(">>> Busyobserver received onError: " + e.getMessage());
onError = true;
int concurrentThreads = threadsRunning.get();
int maxThreads = maxConcurrentThreads.get();
if (concurrentThreads > maxThreads) {
maxConcurrentThreads.compareAndSet(maxThreads, concurrentThreads);
}
threadsRunning.decrementAndGet();
}
代码示例来源:origin: ReactiveX/RxJava
public static void assertError(List<Throwable> list, int index, Class<? extends Throwable> clazz, String message) {
Throwable ex = list.get(index);
if (!clazz.isInstance(ex)) {
AssertionError err = new AssertionError("Type " + clazz + " expected but got " + ex);
err.initCause(ex);
throw err;
}
if (!ObjectHelper.equals(message, ex.getMessage())) {
AssertionError err = new AssertionError("Message " + message + " expected but got " + ex.getMessage());
err.initCause(ex);
throw err;
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void onError(Throwable t) {
upstream.cancel();
list.add(t.getMessage());
}
代码示例来源:origin: ReactiveX/RxJava
static void assertUndeliverableTestException(List<Throwable> list, int index, String message) {
assertTrue(list.get(index).toString(), list.get(index).getCause() instanceof TestException);
assertEquals(message, list.get(index).getCause().getMessage());
}
代码示例来源:origin: ReactiveX/RxJava
static void assertTestException(List<Throwable> list, int index, String message) {
assertTrue(list.get(index).toString(), list.get(index) instanceof TestException);
assertEquals(message, list.get(index).getMessage());
}
代码示例来源:origin: ReactiveX/RxJava
public static void assertError(TestObserver<?> to, int index, Class<? extends Throwable> clazz, String message) {
Throwable ex = to.errors().get(0);
if (ex instanceof CompositeException) {
CompositeException ce = (CompositeException) ex;
List<Throwable> cel = ce.getExceptions();
assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
assertEquals(message, cel.get(index).getMessage());
} else {
fail(ex.toString() + ": not a CompositeException");
}
}
代码示例来源:origin: ReactiveX/RxJava
public static void assertError(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz, String message) {
Throwable ex = ts.errors().get(0);
if (ex instanceof CompositeException) {
CompositeException ce = (CompositeException) ex;
List<Throwable> cel = ce.getExceptions();
assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
assertEquals(message, cel.get(index).getMessage());
} else {
fail(ex.toString() + ": not a CompositeException");
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testOnErrorNotImplementedIsThrown() {
List<Throwable> errors = TestHelper.trackPluginErrors();
Observable.just(1, 2, 3).subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer t1) {
throw new RuntimeException("hello");
}
});
TestHelper.assertError(errors, 0, RuntimeException.class);
assertTrue(errors.get(0).toString(), errors.get(0).getMessage().contains("hello"));
RxJavaPlugins.reset();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void blockingGetErrorTimedOut() {
final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<Integer>();
try {
assertNull(bmo.blockingGetError(1, TimeUnit.NANOSECONDS));
fail("Should have thrown");
} catch (RuntimeException expected) {
assertEquals(TimeoutException.class, expected.getCause().getClass());
assertEquals(timeoutMessage(1, TimeUnit.NANOSECONDS), expected.getCause().getMessage());
}
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void onErrorOnComplete() throws Exception {
fs.onError(new TestException("One"));
fs.onComplete();
try {
fs.get(5, TimeUnit.MILLISECONDS);
} catch (ExecutionException ex) {
assertTrue(ex.toString(), ex.getCause() instanceof TestException);
assertEquals("One", ex.getCause().getMessage());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
@Ignore("Observers can't throw")
public void onErrorNotImplementedFailureSafe() {
try {
new SafeObserver<String>(OBSERVER_ONERROR_NOTIMPLEMENTED()).onError(new SafeObserverTestException("error!"));
fail("expects exception to be thrown");
} catch (Exception e) {
// assertTrue(e instanceof OnErrorNotImplementedException);
assertTrue(e.getCause() instanceof SafeObserverTestException);
assertEquals("error!", e.getCause().getMessage());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
@Ignore("Observers can't throw")
public void onErrorNotImplementedFailureSafe() {
try {
new SafeSubscriber<String>(subscriberOnErrorNotImplemented()).onError(new SafeSubscriberTestException("error!"));
fail("expects exception to be thrown");
} catch (Exception e) {
// assertTrue(e instanceof OnErrorNotImplementedException);
assertTrue(e.getCause() instanceof SafeSubscriberTestException);
assertEquals("error!", e.getCause().getMessage());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normalError() {
Flowable.create(source, BackpressureStrategy.ERROR).subscribe(ts);
source.onNext(1);
source.onNext(2);
source.onComplete();
ts.assertNoValues();
ts.assertError(MissingBackpressureException.class);
ts.assertNotComplete();
Assert.assertEquals("create: could not emit value due to lack of requests", ts.errors().get(0).getMessage());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void errorNotImplementedWithCause() {
OnErrorNotImplementedException ex = new OnErrorNotImplementedException("Message", new TestException("Forced failure"));
assertTrue("" + ex.getCause(), ex.getCause() instanceof TestException);
assertEquals("" + ex.getCause(), "Forced failure", ex.getCause().getMessage());
}
}
内容来源于网络,如有侵权,请联系作者删除!