Exceptions thrown when linking sig-poly methods and indy

John Rose john.r.rose at oracle.com
Wed Aug 24 17:18:36 UTC 2016


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);
 }



More information about the jdk9-dev mailing list