[
https://issues.apache.org/jira/browse/LUCENE-7796?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15979293#comment-15979293
]
Dawid Weiss commented on LUCENE-7796:
-------------------------------------
This is what I think IOUtils.reThrow* methods should look like:
{code}
/**
* An utility method that takes a previously caught
* {@code Throwable} and rethrows either {@code
* IOException} if it the argument was an {@code IOException}
* wraps the argument in a {@code RuntimeException}.
*
* @param th The throwable to rethrow, must not be null.
* @return This method never returns normally, it always throws an exception.
The return
* value of this method can be used for an idiom that informs the compiler
that the code
* below the invocation of this method is unreachable:
* {@code throw reThrow(argument)}.
*/
public static RuntimeException reThrow(Throwable th) throws IOException {
if (th == null) {
throw new AssertionError("reThrow doesn't accept null arguments.");
}
if (th instanceof IOException) {
throw (IOException) th;
}
throw reThrowUnchecked(th);
}
/**
* An utility method that takes a previously caught
* {@code Throwable} and rethrows it if it's an
* unchecked exception or wraps it in a {@code RuntimeException} otherwise.
*
* @param th The throwable to rethrow, must not be null.
* @return This method never returns normally, it always throws an exception.
The return
* value of this method can be used for an idiom that informs the compiler
that the code
* below the invocation of this method is unreachable:
* {@code throw reThrowUnchecked(argument)}.
*/
public static RuntimeException reThrowUnchecked(Throwable th) {
if (th == null) {
throw new AssertionError("reThrowUnchecked doesn't accept null
arguments.");
}
if (th instanceof RuntimeException) {
throw (RuntimeException) th;
}
if (th instanceof Error) {
throw (Error) th;
}
throw new RuntimeException(th);
}
{code}
> Make reThrow idiom declare RuntimeException return type so callers may use it
> in a way that compiler knows subsequent code is unreachable
> -----------------------------------------------------------------------------------------------------------------------------------------
>
> Key: LUCENE-7796
> URL: https://issues.apache.org/jira/browse/LUCENE-7796
> Project: Lucene - Core
> Issue Type: Improvement
> Reporter: Dawid Weiss
> Assignee: Dawid Weiss
> Priority: Trivial
> Fix For: 6.x, master (7.0)
>
>
> A spinoff from LUCENE-7792: reThrow can be declared to return an unchecked
> exception so that callers can choose to use {{throw reThrow(...)}} as an
> idiom to let the compiler know any subsequent code will be unreachable.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]