Exceptions thrown when linking sig-poly methods and indy
dean.long at oracle.com
dean.long at oracle.com
Wed Aug 24 18:37:00 UTC 2016
On 8/24/16 10:18 AM, John Rose wrote:
> On Aug 24, 2016, at 10:04 AM, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>> So we are talking about this kind of catch and re-throw pattern:
>>
>> try {
>> x();
>> } catch (Throwable t) {
>> if (t instanceof Error) {
>> // Pass through any Error
>> throw (Error) t;
>> }
>> // Wrap any Throwable that is not a subclass of Error
>> throw new LinkageError(t.getMessage(), t);
>> }
> Yes.
>
> System-level methods should have "throws Throwable", in which
> case this equivalent formulation is slightly more future-proof IMO:
>
> try {
> x();
> } catch (Throwable t) {
> if (!(t instanceof Exception)) {
> // Pass through any Error (or other non-Exception if such a thing exists)
> throw t;
> }
> // Wrap any Throwable that is not a subclass of Error
> throw new LinkageError(t.getMessage(), t);
> }
>
Related to this, I always thought that java.lang.reflect.Method.invoke
should do something similar when wrapping with
InvocationTargetException. Does anyone think the Method.invoke spec or
behavior also needs clarification?
dl
More information about the jdk9-dev
mailing list