[9] RFR (M): 8050052: Small cleanups in java.lang.invoke code (original) (raw)
John Rose john.r.rose at oracle.com
Fri Jul 18 01:54:48 UTC 2014
- Previous message: [9] RFR (M): 8050052: Small cleanups in java.lang.invoke code
- Next message: [9] RFR (M): 8050052: Small cleanups in java.lang.invoke code
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
FTR, I captured this issue:
https://bugs.openjdk.java.net/browse/JDK-8051294
(Wish they were all so easy to catch.)
— John
On Jul 17, 2014, at 5:12 PM, John Rose <john.r.rose at oracle.com> wrote:
On Jul 16, 2014, at 11:20 AM, Peter Levart <peter.levart at gmail.com> wrote:
An alternative could be:
public Throwable throwIfUnchecked() { if (this instanceof RuntimeException) throw (RuntimeException) this; if (this instanceof Error) throw (Error) this; return this; } Then use it like: try { ... } catch (Throwable t) { throw new WrapperException(t.throwIfUnchecked()); } I like this one. (I wish we could declare This types, so that TYPEOF[t.throwIfUnchecked()] == TYPEOF[t].) It puts the throw of the "less dangerous" exception type inside the subroutine, making the wrapping and the "more dangerous" (more ad hoc) exception be explicit and in-line. To complete the picture, add: public Throwable throwIf(Class exClass) throws X { if (exClass.isInstance(this)) throw exClass.cast(this); return this; } ...to be used as: try { ... } catch (Throwable t) { t.throwIfUnchecked().throwIf(X.class).throwIf(Y.class).throwIf(Z.class); throw new WrapperException(t); } Or some other combination of sequential and/or fluent calls. — John
- Previous message: [9] RFR (M): 8050052: Small cleanups in java.lang.invoke code
- Next message: [9] RFR (M): 8050052: Small cleanups in java.lang.invoke code
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]