/** * Invokes the method and retrieves its return {@link Reply}. * * @param obj an bot or extension that this method is invoked with * @return a {@link Function} which returns the {@link Reply} returned by the given method */ private Function<? super Method, AbilityExtension> returnExtension(Object obj) { return method -> { try { return (AbilityExtension) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { BotLogger.error("Could not add ability extension", TAG, e); throw propagate(e); } }; }
/** * Propagates {@code throwable} exactly as-is, if and only if it is an * instance of {@link RuntimeException}, {@link Error}, {@code declaredType1}, * or {@code declaredType2}. In the unlikely case that you have three or more * declared checked exception types, you can handle them all by invoking these * methods repeatedly. See usage example in {@link * #propagateIfPossible(Throwable, Class)}. * * @param throwable the Throwable to possibly propagate * @param declaredType1 any checked exception type declared by the calling * method * @param declaredType2 any other checked exception type declared by the * calling method */ public static <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible(@Nullable Throwable throwable, Class<X1> declaredType1, Class<X2> declaredType2) throws X1, X2 { checkNotNull(declaredType2); propagateIfInstanceOf(throwable, declaredType1); propagateIfPossible(throwable, declaredType2); }
/** * Propagates {@code throwable} as-is if it is an instance of * {@link RuntimeException} or {@link Error}, or else as a last resort, wraps * it in a {@code RuntimeException} then propagates. * <p> * This method always throws an exception. The {@code RuntimeException} return * type is only for client code to make Java type system happy in case a * return value is required by the enclosing method. Example usage: * <pre> * T doSomething() { * try { * return someMethodThatCouldThrowAnything(); * } catch (IKnowWhatToDoWithThisException e) { * return handle(e); * } catch (Throwable t) { * throw Throwables.propagate(t); * } * } * </pre> * * @param throwable the Throwable to propagate * @return nothing will ever be returned; this return type is only for your * convenience, as illustrated in the example above */ public static RuntimeException propagate(Throwable throwable) { propagateIfPossible(checkNotNull(throwable)); throw new RuntimeException(throwable); }
/** * Propagates {@code throwable} exactly as-is, if and only if it is an * instance of {@link RuntimeException}, {@link Error}, {@code declaredType1}, * or {@code declaredType2}. In the unlikely case that you have three or more * declared checked exception types, you can handle them all by invoking these * methods repeatedly. See usage example in {@link * #propagateIfPossible(Throwable, Class)}. * * @param throwable the Throwable to possibly propagate * @param declaredType1 any checked exception type declared by the calling * method * @param declaredType2 any other checked exception type declared by the * calling method */ public static <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible(@Nullable Throwable throwable, Class<X1> declaredType1, Class<X2> declaredType2) throws X1, X2 { checkNotNull(declaredType2); propagateIfInstanceOf(throwable, declaredType1); propagateIfPossible(throwable, declaredType2); }
/** * Propagates {@code throwable} as-is if it is an instance of * {@link RuntimeException} or {@link Error}, or else as a last resort, wraps * it in a {@code RuntimeException} then propagates. * <p> * This method always throws an exception. The {@code RuntimeException} return * type is only for client code to make Java type system happy in case a * return value is required by the enclosing method. Example usage: * <pre> * T doSomething() { * try { * return someMethodThatCouldThrowAnything(); * } catch (IKnowWhatToDoWithThisException e) { * return handle(e); * } catch (Throwable t) { * throw Throwables.propagate(t); * } * } * </pre> * * @param throwable the Throwable to propagate * @return nothing will ever be returned; this return type is only for your * convenience, as illustrated in the example above */ public static RuntimeException propagate(Throwable throwable) { propagateIfPossible(checkNotNull(throwable)); throw new RuntimeException(throwable); }
/** * Invokes the method and retrieves its return {@link Ability}. * * @param obj an bot or extension that this method is invoked with * @return a {@link Function} which returns the {@link Ability} returned by the given method */ private Function<? super Method, Ability> returnAbility(Object obj) { return method -> { try { return (Ability) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { BotLogger.error("Could not add ability", TAG, e); throw propagate(e); } }; }
/** * Propagates {@code throwable} exactly as-is, if and only if it is an * instance of {@link RuntimeException}, {@link Error}, {@code declaredType1}, * or {@code declaredType2}. In the unlikely case that you have three or more * declared checked exception types, you can handle them all by invoking these * methods repeatedly. See usage example in {@link * #propagateIfPossible(Throwable, Class)}. * * @param throwable the Throwable to possibly propagate * @param declaredType1 any checked exception type declared by the calling * method * @param declaredType2 any other checked exception type declared by the * calling method */ public static <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible(@Nullable Throwable throwable, Class<X1> declaredType1, Class<X2> declaredType2) throws X1, X2 { checkNotNull(declaredType2); propagateIfInstanceOf(throwable, declaredType1); propagateIfPossible(throwable, declaredType2); }
/** * Propagates {@code throwable} as-is if it is an instance of * {@link RuntimeException} or {@link Error}, or else as a last resort, wraps * it in a {@code RuntimeException} then propagates. * <p> * This method always throws an exception. The {@code RuntimeException} return * type is only for client code to make Java type system happy in case a * return value is required by the enclosing method. Example usage: * <pre> * T doSomething() { * try { * return someMethodThatCouldThrowAnything(); * } catch (IKnowWhatToDoWithThisException e) { * return handle(e); * } catch (Throwable t) { * throw Throwables.propagate(t); * } * } * </pre> * * @param throwable the Throwable to propagate * @return nothing will ever be returned; this return type is only for your * convenience, as illustrated in the example above */ public static RuntimeException propagate(Throwable throwable) { propagateIfPossible(checkNotNull(throwable)); throw new RuntimeException(throwable); }
/** * Invokes the method and retrieves its return {@link Reply}. * * @param obj an bot or extension that this method is invoked with * @return a {@link Function} which returns the {@link Reply} returned by the given method */ private Function<? super Method, Reply> returnReply(Object obj) { return method -> { try { return (Reply) method.invoke(obj); } catch (IllegalAccessException | InvocationTargetException e) { BotLogger.error("Could not add reply", TAG, e); throw propagate(e); } }; }
/** * Propagates {@code throwable} exactly as-is, if and only if it is an * instance of {@link RuntimeException}, {@link Error}, {@code declaredType1}, * or {@code declaredType2}. In the unlikely case that you have three or more * declared checked exception types, you can handle them all by invoking these * methods repeatedly. See usage example in {@link * #propagateIfPossible(Throwable, Class)}. * * @param throwable the Throwable to possibly propagate * @param declaredType1 any checked exception type declared by the calling * method * @param declaredType2 any other checked exception type declared by the * calling method */ public static <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible(@Nullable Throwable throwable, Class<X1> declaredType1, Class<X2> declaredType2) throws X1, X2 { checkNotNull(declaredType2); propagateIfInstanceOf(throwable, declaredType1); propagateIfPossible(throwable, declaredType2); }
/** * Propagates {@code throwable} as-is if it is an instance of * {@link RuntimeException} or {@link Error}, or else as a last resort, wraps * it in a {@code RuntimeException} then propagates. * <p> * This method always throws an exception. The {@code RuntimeException} return * type is only for client code to make Java type system happy in case a * return value is required by the enclosing method. Example usage: * <pre> * T doSomething() { * try { * return someMethodThatCouldThrowAnything(); * } catch (IKnowWhatToDoWithThisException e) { * return handle(e); * } catch (Throwable t) { * throw Throwables.propagate(t); * } * } * </pre> * * @param throwable the Throwable to propagate * @return nothing will ever be returned; this return type is only for your * convenience, as illustrated in the example above */ public static RuntimeException propagate(Throwable throwable) { propagateIfPossible(checkNotNull(throwable)); throw new RuntimeException(throwable); }
} catch (IllegalStateException e) { BotLogger.error(TAG, "Duplicate names found while registering abilities. Make sure that the abilities declared don't clash with the reserved ones.", e); throw propagate(e);
/** * Gets the user with the specified username. If user was not found, the bot will send a message on Telegram. * * @param username the username of the required user * @param ctx the message context with the originating user * @return the id of the user */ protected int getUserIdSendError(String username, MessageContext ctx) { try { return getUser(username).getId(); } catch (IllegalStateException ex) { silent.send(getLocalizedMessage(USER_NOT_FOUND, ctx.user().getLanguageCode(), username), ctx.chatId()); throw propagate(ex); } }
@Override public void run() { try { wrapped.call(); } catch (Exception e) { Throwables.propagate(e); } } };
@Override public void run() { try { wrapped.call(); } catch (Exception e) { Throwables.propagate(e); } } };
@Override public void run() { try { wrapped.call(); } catch (Exception e) { Throwables.propagate(e); } } };
@Override public void run() { try { wrapped.call(); } catch (Exception e) { Throwables.propagate(e); } } };
@Override public void run() { try { delegate.run(); } catch (Throwable t) { setException(t); throw Throwables.propagate(t); } } }
@Override public void run() { try { delegate.run(); } catch (Throwable t) { setException(t); throw Throwables.propagate(t); } } }
@Override public void run() { try { delegate.run(); } catch (Throwable t) { setException(t); throw Throwables.propagate(t); } } }