org.jooby.funzy.Try.unwrap()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(279)

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

Try.unwrap介绍

[英]In case of failure unwrap the exception provided by calling Throwable#getCause(). Useful for clean/shorter stackstrace. Example for java.lang.reflect.InvocationTargetException:

  1. Try.run(() -> ).unwrap(InvocationTargetException.class)
  2. .throwException();
  3. }

[中]如果失败,请打开调用Throwable#getCause()提供的异常。适用于干净/较短的堆叠距离。java示例。朗,反思一下。InvocationTargetException:

  1. Try.run(() -> ).unwrap(InvocationTargetException.class)
  2. .throwException();
  3. }

代码示例

代码示例来源:origin: jooby-project/jooby

  1. @Override
  2. public void tryRun() throws Throwable {
  3. if (dep == null) {
  4. return;
  5. }
  6. Try.run(() -> {
  7. Optional<Method> shutdown = Arrays.stream(dep.getClass().getMethods())
  8. .filter(m -> m.getName().startsWith("shutdown")
  9. && m.getParameterCount() == 0
  10. && Modifier.isPublic(m.getModifiers()))
  11. .findFirst();
  12. if (shutdown.isPresent()) {
  13. log.debug("stopping {}", dep);
  14. shutdown.get().invoke(dep);
  15. } else {
  16. log.debug("no shutdown method found for: {}", dep);
  17. }
  18. }).unwrap(InvocationTargetException.class)
  19. .onComplete(() -> this.dep = null)
  20. .throwException();
  21. }

代码示例来源:origin: jooby-project/jooby

  1. method.setAccessible(true);
  2. method.invoke(owner);
  3. }).unwrap(InvocationTargetException.class)
  4. .throwException();
  5. });

代码示例来源:origin: jooby-project/jooby

  1. private void tryOption(final Object source, final Config config, final Method option) {
  2. Try.run(() -> {
  3. String optionName = option.getName().replace("set", "");
  4. Object optionValue = config.getAnyRef(optionName);
  5. Class<?> optionType = Primitives.wrap(option.getParameterTypes()[0]);
  6. if (Number.class.isAssignableFrom(optionType) && optionValue instanceof String) {
  7. // either a byte or time unit
  8. try {
  9. optionValue = config.getBytes(optionName);
  10. } catch (ConfigException.BadValue ex) {
  11. optionValue = config.getDuration(optionName, TimeUnit.MILLISECONDS);
  12. }
  13. if (optionType == Integer.class) {
  14. // to int
  15. optionValue = ((Number) optionValue).intValue();
  16. }
  17. }
  18. log.debug("{}.{}({})", source.getClass().getSimpleName(), option.getName(), optionValue);
  19. option.invoke(source, optionValue);
  20. }).unwrap(InvocationTargetException.class)
  21. .throwException();
  22. }

代码示例来源:origin: jooby-project/jooby

  1. Files.copy(from, to);
  2. }).unwrap(InvocationTargetException.class)
  3. .throwException();

代码示例来源:origin: org.jooby/funzy

  1. @Override public <X extends Throwable> Value<V> unwrap(Class<? extends X> type) {
  2. return (Value<V>) super.unwrap(type);
  3. }

代码示例来源:origin: org.jooby/funzy

  1. @Override public Value<V> unwrap(final Throwing.Predicate<Throwable> predicate) {
  2. return (Value<V>) super.unwrap(predicate);
  3. }

代码示例来源:origin: org.jooby/funzy

  1. /**
  2. * In case of failure unwrap the exception provided by calling {@link Throwable#getCause()}.
  3. * Useful for clean/shorter stackstrace.
  4. *
  5. * Example for {@link java.lang.reflect.InvocationTargetException}:
  6. *
  7. * <pre>{@code
  8. * Try.run(() -> {
  9. * Method m = ...;
  10. * m.invoke(...); //might throw InvocationTargetException
  11. * }).unwrap(InvocationTargetException.class)
  12. * .throwException();
  13. * }</pre>
  14. *
  15. * @param type Exception filter.
  16. * @param <X> Exception type.
  17. * @return This try for success or a new failure with exception unwrap.
  18. */
  19. public <X extends Throwable> Try unwrap(Class<? extends X> type) {
  20. return unwrap(type::isInstance);
  21. }

代码示例来源:origin: org.jooby/jooby-aws

  1. @Override
  2. public void tryRun() throws Throwable {
  3. if (dep == null) {
  4. return;
  5. }
  6. Try.run(() -> {
  7. Optional<Method> shutdown = Arrays.stream(dep.getClass().getMethods())
  8. .filter(m -> m.getName().startsWith("shutdown")
  9. && m.getParameterCount() == 0
  10. && Modifier.isPublic(m.getModifiers()))
  11. .findFirst();
  12. if (shutdown.isPresent()) {
  13. log.debug("stopping {}", dep);
  14. shutdown.get().invoke(dep);
  15. } else {
  16. log.debug("no shutdown method found for: {}", dep);
  17. }
  18. }).unwrap(InvocationTargetException.class)
  19. .onComplete(() -> this.dep = null)
  20. .throwException();
  21. }

代码示例来源:origin: org.jooby/jooby

  1. method.setAccessible(true);
  2. method.invoke(owner);
  3. }).unwrap(InvocationTargetException.class)
  4. .throwException();
  5. });

代码示例来源:origin: org.jooby/jooby-jetty

  1. private void tryOption(final Object source, final Config config, final Method option) {
  2. Try.run(() -> {
  3. String optionName = option.getName().replace("set", "");
  4. Object optionValue = config.getAnyRef(optionName);
  5. Class<?> optionType = Primitives.wrap(option.getParameterTypes()[0]);
  6. if (Number.class.isAssignableFrom(optionType) && optionValue instanceof String) {
  7. // either a byte or time unit
  8. try {
  9. optionValue = config.getBytes(optionName);
  10. } catch (ConfigException.BadValue ex) {
  11. optionValue = config.getDuration(optionName, TimeUnit.MILLISECONDS);
  12. }
  13. if (optionType == Integer.class) {
  14. // to int
  15. optionValue = ((Number) optionValue).intValue();
  16. }
  17. }
  18. log.debug("{}.{}({})", source.getClass().getSimpleName(), option.getName(), optionValue);
  19. option.invoke(source, optionValue);
  20. }).unwrap(InvocationTargetException.class)
  21. .throwException();
  22. }

相关文章