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

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

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

Try.throwException介绍

[英]Propagate/throw the exception in case of failure.
[中]在发生故障时传播/抛出异常。

代码示例

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

  1. private Jooby hackInjector(final Jooby app) {
  2. Try.run(() -> {
  3. Field field = Jooby.class.getDeclaredField("injector");
  4. field.setAccessible(true);
  5. Injector injector = proxyInjector(getClass().getClassLoader(), registry);
  6. field.set(app, injector);
  7. registry.put(Key.get(Injector.class), injector);
  8. }).throwException();
  9. return app;
  10. }

代码示例来源: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. private static void copy(final InputStream in, final OutputStream out) {
  2. Try.of(in, out)
  3. .run(ByteStreams::copy)
  4. .throwException();
  5. }

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

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

代码示例来源: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. .throwException();

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

  1. private void handleErr(final Throwable cause) {
  2. Try.run(() -> {
  3. if (SILENT.test(cause)) {
  4. log.debug("execution of WS" + path() + " resulted in exception", cause);
  5. } else {
  6. exceptionCallback.onError(cause);
  7. }
  8. })
  9. .onComplete(() -> cleanup(cause))
  10. .throwException();
  11. }

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

  1. @Override
  2. public void handle(final Request req, final Response rsp, final Optional<Throwable> cause) {
  3. if (handle.isClosed()) {
  4. logger.warn("closed handle: {}", handle);
  5. } else {
  6. logger.debug("closing handling: {}", handle);
  7. Try.of(handle)
  8. .run(h -> {
  9. if (h.isInTransaction()) {
  10. if (cause.isPresent()) {
  11. logger.debug("rollback transaction: {}", handle, cause.get());
  12. h.rollback();
  13. } else {
  14. logger.debug("commit transaction {}", handle);
  15. h.commit();
  16. }
  17. }
  18. }).throwException();
  19. }
  20. }
  21. }

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

  1. /**
  2. * Execute the given nodejs callback and automatically releaseNow v8 and nodejs resources.
  3. *
  4. * @param basedir Base dir where to deploy a library.
  5. * @param callback Nodejs callback.
  6. */
  7. public static void run(final File basedir, final Throwing.Consumer<Nodejs> callback) {
  8. Nodejs node = new Nodejs(basedir);
  9. Try.run(() -> callback.accept(node))
  10. .onComplete(node::release)
  11. .throwException();
  12. }
  13. }

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

  1. public MockUnit run(final Block... blocks) throws Exception {
  2. for (Block block : this.blocks) {
  3. Try.run(() -> block.run(this))
  4. .throwException();
  5. }
  6. mockClasses.forEach(PowerMock::replay);
  7. partialMocks.forEach(PowerMock::replay);
  8. mocks.forEach(EasyMock::replay);
  9. for (Block main : blocks) {
  10. Try.run(() -> main.run(this)).throwException();
  11. }
  12. mocks.forEach(EasyMock::verify);
  13. partialMocks.forEach(PowerMock::verify);
  14. mockClasses.forEach(PowerMock::verify);
  15. return this;
  16. }

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

  1. Runtime.getRuntime().addShutdownHook(new Thread(() -> Try.run(watcher::stop)
  2. .onComplete(() -> connection.close())
  3. .throwException()));
  4. watcher.start();

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

  1. caseSensitiveRouting)
  2. .accept(it))
  3. .throwException();

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

  1. private Executor executor() {
  2. if (executor == null) {
  3. if (this.host.startsWith("https://")) {
  4. Try.run(() -> {
  5. SSLContext sslContext = SSLContexts.custom()
  6. .loadTrustMaterial(null, (chain, authType) -> true)
  7. .build();
  8. builder.setSSLContext(sslContext);
  9. builder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);
  10. }).throwException();
  11. }
  12. client = builder.build();
  13. executor = Executor.newInstance(client);
  14. if (creds != null) {
  15. executor.auth(creds);
  16. }
  17. }
  18. return executor;
  19. }

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

  1. private Jooby hackInjector(final Jooby app) {
  2. Try.run(() -> {
  3. Field field = Jooby.class.getDeclaredField("injector");
  4. field.setAccessible(true);
  5. Injector injector = proxyInjector(getClass().getClassLoader(), registry);
  6. field.set(app, injector);
  7. registry.put(Key.get(Injector.class), injector);
  8. }).throwException();
  9. return app;
  10. }

代码示例来源: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. private static void copy(final InputStream in, final OutputStream out) {
  2. Try.of(in, out)
  3. .run(ByteStreams::copy)
  4. .throwException();
  5. }

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

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

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

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

  1. private void handleErr(final Throwable cause) {
  2. Try.run(() -> {
  3. if (SILENT.test(cause)) {
  4. log.debug("execution of WS" + path() + " resulted in exception", cause);
  5. } else {
  6. exceptionCallback.onError(cause);
  7. }
  8. })
  9. .onComplete(() -> cleanup(cause))
  10. .throwException();
  11. }

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

  1. /**
  2. * Execute the given nodejs callback and automatically releaseNow v8 and nodejs resources.
  3. *
  4. * @param basedir Base dir where to deploy a library.
  5. * @param callback Nodejs callback.
  6. */
  7. public static void run(final File basedir, final Throwing.Consumer<Nodejs> callback) {
  8. Nodejs node = new Nodejs(basedir);
  9. Try.run(() -> callback.accept(node))
  10. .onComplete(node::release)
  11. .throwException();
  12. }
  13. }

相关文章