Add ExceptionUtils.throwUnchecked(T) where T extends Throwable, and
deprecate Object version
This commit is contained in:
parent
1a45003b8b
commit
1abc85cb2d
|
@ -74,6 +74,7 @@ The <action> type attribute can be add,update,fix,remove.
|
||||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.failableStream(T...).</action>
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.failableStream(T...).</action>
|
||||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add FailableSupplier.nul().</action>
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add FailableSupplier.nul().</action>
|
||||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Suppliers.nul().</action>
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Suppliers.nul().</action>
|
||||||
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add ExceptionUtils.throwUnchecked(T) where T extends Throwable, and deprecate Object version.</action>
|
||||||
<!-- UPDATE -->
|
<!-- UPDATE -->
|
||||||
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-parent from 58 to 64.</action>
|
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump commons-parent from 58 to 64.</action>
|
||||||
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.easymock:easymock from 5.1.0 to 5.2.0 #1104.</action>
|
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.easymock:easymock from 5.1.0 to 5.2.0 #1104.</action>
|
||||||
|
|
|
@ -971,7 +971,9 @@ public class ExceptionUtils {
|
||||||
* @param throwable the throwable to test and throw or return.
|
* @param throwable the throwable to test and throw or return.
|
||||||
* @return the given throwable.
|
* @return the given throwable.
|
||||||
* @since 3.13.0
|
* @since 3.13.0
|
||||||
|
* @deprecated Use {@link #throwUnchecked(Throwable)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static <T> T throwUnchecked(final T throwable) {
|
public static <T> T throwUnchecked(final T throwable) {
|
||||||
if (throwable instanceof RuntimeException) {
|
if (throwable instanceof RuntimeException) {
|
||||||
throw (RuntimeException) throwable;
|
throw (RuntimeException) throwable;
|
||||||
|
@ -982,6 +984,24 @@ public class ExceptionUtils {
|
||||||
return throwable;
|
return throwable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether the specified {@link Throwable} is unchecked and throws it if so.
|
||||||
|
*
|
||||||
|
* @param <T> The Throwable type.
|
||||||
|
* @param throwable the throwable to test and throw or return.
|
||||||
|
* @return the given throwable.
|
||||||
|
* @since 3.14.0
|
||||||
|
*/
|
||||||
|
public static <T extends Throwable> T throwUnchecked(final T throwable) {
|
||||||
|
if (throwable instanceof RuntimeException) {
|
||||||
|
throw (RuntimeException) throwable;
|
||||||
|
}
|
||||||
|
if (throwable instanceof Error) {
|
||||||
|
throw (Error) throwable;
|
||||||
|
}
|
||||||
|
return throwable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws a checked exception without adding the exception to the throws
|
* Throws a checked exception without adding the exception to the throws
|
||||||
* clause of the calling method. For checked exceptions, this method throws
|
* clause of the calling method. For checked exceptions, this method throws
|
||||||
|
|
Loading…
Reference in New Issue