java.lang.Throwable.toString()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(199)

本文整理了Java中java.lang.Throwable.toString()方法的一些代码示例,展示了Throwable.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Throwable.toString()方法的具体详情如下:
包路径:java.lang.Throwable
类名称:Throwable
方法名:toString

Throwable.toString介绍

[英]Returns a short description of this throwable. The result is the concatenation of:

  • the Class#getName() of the class of this object
  • ": " (a colon and a space)
  • the result of invoking this object's #getLocalizedMessagemethod
    If getLocalizedMessage returns null, then just the class name is returned.
    [中]返回此可丢弃项的简短描述。结果是以下各项的串联:
    *此对象的类的类#getName()
    *“:”(冒号和空格)
    *调用此对象的#getLocalizedMessagemethod的结果
    如果getLocalizedMessage返回null,则只返回类名。

代码示例

代码示例来源:origin: apache/incubator-dubbo

public IOExceptionWrapper(Throwable cause) {
  super(cause.toString());
  _cause = cause;
}

代码示例来源:origin: spring-projects/spring-framework

@Override
  public String toString() {
    return getCause().toString();
  }
}

代码示例来源:origin: ReactiveX/RxJava

static void assertNPE(List<Throwable> list, int index) {
  assertTrue(list.get(index).toString(), list.get(index) instanceof NullPointerException);
}

代码示例来源: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(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz) {
  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)));
  } else {
    fail(ex.toString() + ": not a CompositeException");
  }
}

代码示例来源: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

public static void assertError(TestObserver<?> to, int index, Class<? extends Throwable> clazz) {
  Throwable ex = to.errors().get(0);
  try {
    if (ex instanceof CompositeException) {
      CompositeException ce = (CompositeException) ex;
      List<Throwable> cel = ce.getExceptions();
      assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
    } else {
      fail(ex.toString() + ": not a CompositeException");
    }
  } catch (AssertionError e) {
    ex.printStackTrace();
    throw e;
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void disposeIndicated() {
  TestSubscriber<Object> ts = new TestSubscriber<Object>();
  ts.cancel();
  try {
    ts.assertResult(1);
    throw new RuntimeException("Should have thrown!");
  } catch (Throwable ex) {
    assertTrue(ex.toString(), ex.toString().contains("disposed!"));
  }
}

代码示例来源: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 concatDelayErrorFlowableError() {
  TestSubscriber<Integer> ts = TestSubscriber.create();
  Flowable.concatDelayError(
      withError(Flowable.just(withError(Flowable.just(1)), withError(Flowable.just(2)))))
  .subscribe(ts);
  ts.assertValues(1, 2);
  ts.assertError(CompositeException.class);
  ts.assertNotComplete();
  CompositeException ce = (CompositeException)ts.errors().get(0);
  List<Throwable> cex = ce.getExceptions();
  assertEquals(3, cex.size());
  assertTrue(cex.get(0).toString(), cex.get(0) instanceof TestException);
  assertTrue(cex.get(1).toString(), cex.get(1) instanceof TestException);
  assertTrue(cex.get(2).toString(), cex.get(2) instanceof TestException);
}

代码示例来源:origin: ReactiveX/RxJava

@Override
public void onSubscribe(Subscription s) {
  @SuppressWarnings("unchecked")
  QueueSubscription<Integer> qs = (QueueSubscription<Integer>)s;
  qs.requestFusion(QueueFuseable.ANY);
  try {
    assertEquals(1, qs.poll().intValue());
  } catch (Throwable ex) {
    fail(ex.toString());
  }
  qs.clear();
  try {
    assertNull(qs.poll());
  } catch (Throwable ex) {
    fail(ex.toString());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Override
public void onSubscribe(Disposable d) {
  @SuppressWarnings("unchecked")
  QueueDisposable<Integer> qd = (QueueDisposable<Integer>)d;
  qd.requestFusion(QueueFuseable.ANY);
  try {
    assertEquals(1, qd.poll().intValue());
  } catch (Throwable ex) {
    fail(ex.toString());
  }
  qd.clear();
  try {
    assertNull(qd.poll());
  } catch (Throwable ex) {
    fail(ex.toString());
  }
}

代码示例来源:origin: ReactiveX/RxJava

@SuppressWarnings("unchecked")
@Test
public void arrayDelayError() {
  Publisher<Integer>[] sources = new Publisher[] {
      Flowable.just(1),
      null,
      Flowable.range(2, 3),
      Flowable.error(new TestException()),
      Flowable.empty()
  };
  TestSubscriber<Integer> ts = Flowable.concatArrayDelayError(sources).test();
  ts.assertFailure(CompositeException.class, 1, 2, 3, 4);
  CompositeException composite = (CompositeException)ts.errors().get(0);
  List<Throwable> list = composite.getExceptions();
  assertTrue(list.get(0).toString(), list.get(0) instanceof NullPointerException);
  assertTrue(list.get(1).toString(), list.get(1) instanceof TestException);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void doubleError() {
  List<Throwable> errors = TestHelper.trackPluginErrors();
  try {
    new ParallelInvalid()
    .runOn(ImmediateThinScheduler.INSTANCE)
    .sequential()
    .test()
    .assertFailure(TestException.class);
    assertFalse(errors.isEmpty());
    for (Throwable ex : errors) {
      assertTrue(ex.toString(), ex.getCause() instanceof TestException);
    }
  } finally {
    RxJavaPlugins.reset();
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void doubleError() {
  List<Throwable> errors = TestHelper.trackPluginErrors();
  try {
    new ParallelInvalid()
    .doOnNext(Functions.emptyConsumer())
    .sequential()
    .test()
    .assertFailure(TestException.class);
    assertFalse(errors.isEmpty());
    for (Throwable ex : errors) {
      assertTrue(ex.toString(), ex.getCause() instanceof TestException);
    }
  } finally {
    RxJavaPlugins.reset();
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void valueOfOnErrorIsNull() {
  Notification<Integer> notification = Notification.createOnError(new TestException());
  assertNull(notification.getValue());
  assertTrue(notification.getError().toString(), notification.getError() instanceof TestException);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void offer() {
  PublishProcessor<Integer> pp = PublishProcessor.create();
  TestSubscriber<Integer> ts = pp.test(0);
  assertFalse(pp.offer(1));
  ts.request(1);
  assertTrue(pp.offer(1));
  assertFalse(pp.offer(2));
  ts.cancel();
  assertTrue(pp.offer(2));
  ts = pp.test(0);
  assertTrue(pp.offer(null));
  ts.assertFailure(NullPointerException.class);
  assertTrue(pp.hasThrowable());
  assertTrue(pp.getThrowable().toString(), pp.getThrowable() instanceof NullPointerException);
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void offer() {
  BehaviorProcessor<Integer> pp = BehaviorProcessor.create();
  TestSubscriber<Integer> ts = pp.test(0);
  assertFalse(pp.offer(1));
  ts.request(1);
  assertTrue(pp.offer(1));
  assertFalse(pp.offer(2));
  ts.cancel();
  assertTrue(pp.offer(2));
  ts = pp.test(1);
  assertTrue(pp.offer(null));
  ts.assertFailure(NullPointerException.class, 2);
  assertTrue(pp.hasThrowable());
  assertTrue(pp.getThrowable().toString(), pp.getThrowable() instanceof NullPointerException);
}

相关文章