diff --git a/src/main/java/org/apache/commons/lang3/Functions.java b/src/main/java/org/apache/commons/lang3/Functions.java index eeed548a9..db422ad16 100644 --- a/src/main/java/org/apache/commons/lang3/Functions.java +++ b/src/main/java/org/apache/commons/lang3/Functions.java @@ -491,9 +491,27 @@ public class Functions { } /** - * Rethrows a {@link Throwable} as an unchecked exception. - * @param pThrowable The throwable to rethrow - * @return Never returns anything, this method never terminates normally + *

Rethrows a {@link Throwable} as an unchecked exception. If the argument is + * already unchecked, namely a {@code RuntimeException} or {@code Error} then + * the argument will be rethrown without modification. If the exception is + * {@code IOException} then it will be wrapped into a {@code UncheckedIOException}. + * In every other cases the exception will be wrapped into a {@code + * UndeclaredThrowableException}

+ * + *

Note that there is a declared return type for this method, even though it + * never returns. The reason for that is to support the usual pattern:

+ * + *
+     *      throw rethrow(myUncheckedException);
+     * 
+ * + *

instead of just calling the method. This pattern may help the Java compiler to + * recognize that at that point an exception will be thrown and the code flow + * analysis will not demand otherwise mandatory commands that could follow the + * method call, like a {@code return} statement from a value returning method.

+ * + * @param pThrowable The throwable to rethrow possibly wrapped into an unchecked exception + * @return Never returns anything, this method never terminates normally. */ public static RuntimeException rethrow(Throwable pThrowable) { if (pThrowable == null) {