On 07/14/2014 07:03 AM, David Holmes wrote:
On 12/07/2014 3:56 AM, Remi Forax wrote:
On 07/11/2014 06:18 PM, Vladimir Ivanov wrote:
http://cr.openjdk.java.net/~vlivanov/8050052/webrev.00
https://bugs.openjdk.java.net/browse/JDK-8050052
I've found myself writing the very same code as
MethodHandleStatics.uncaughException several times
and I wonder if it should not be an instance method of Throwable.
Something like:
public <E extends Throwable> E rethrow(Function<? super Throwable, ?
extends E> uncaughtHandler) {
if (this instanceof RuntimeException) {
throw (RuntimeException)this;
}
if (this instanceof Error) {
throw (Error)this;
}
return uncaughtHandler.apply(this);
Rethrowing is one thing but what is this uncaughtHandler supposed to
be doing?
Sometimes there is a catch(Exception) or a catch(Throwable) that was
already done
in the code of an API you use so the exception kind you get is too broad,
by example, using the reflection:
try {
return method.invoke(...);
} catch(InvocationTargetException e) {
throw e.getCause().rethrow(...); // here e.getCause() can store any
Throwable
}
rethrow cleanly separate the checked exception from the unchecked ones,
so the user can manage exceptions correctly.
At this level you expect all these exceptions to be "uncaught" and
propagate up.
I expect that either there is a dedicated exception, like SAXException
for an XML parser,
UndeclaredThrowableException for a reflect.Proxy, that can tunnel
checked exceptions
in the signature of the method that calls rethrow or that the user want
to suppress
the checked exception using by example an IOError to wrap an IOException.
so I expect the code to be something like
throw e.rethrow(SAXException::new); or
throw e.rethrow(IOError::new);
David
-----
Rémi
}
in that case, throw uncaughtException(ex) can be replaced by throw
ex.rethrow(::newInternalError);
cheers,
Rémi
Numerous small code cleanups in java.lang.invoke package.
Testing: jtreg, nashorn, octane w/ "-ea -esa" and
COMPILE_THRESHOLD={0,30}.
Reviewed-by: vlivanov, ?
Contributed-by: john.r.r...@oracle.com
Thanks!
Best regards,
Vladimir Ivanov
_______________________________________________
mlvm-dev mailing list
mlvm-...@openjdk.java.net
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev