New protocol for disabling exception suppression
brucechapman at paradise.net.nz
brucechapman at paradise.net.nz
Sun Apr 3 15:11:03 PDT 2011
Quoting Rémi Forax <forax at univ-mlv.fr>:
> On 04/03/2011 11:29 PM, brucechapman at paradise.net.nz wrote:
> > Quoting Rémi Forax<forax at univ-mlv.fr>:
> >> On 04/02/2011 03:21 AM, joe.darcy at oracle.com wrote:
> >>> As part of the library support for the try-with-resources
> >>> several API changes were made to Throwable including an
> >>> method to allow suppressed exceptions to be recorded. As previously
> >>> discussed on coin-dev , to support VM needs for reusable
> >>> objects, a protocol was devised to disable the suppression
> >> so
> >>> that a zero-length array would be returned from getSuppressed even
> >>> addSuppressed was called with a valid argument. The mechanism was a
> >> bit
> >>> of a kludge, relying on an initial call to addSuppressed with a
> >>> argument, and the design was called out as such.  I'm happy to
> >> report
> >>> the JSR 334 expert group has devised a more elegant protocol to
> >> disable
> >>> exception suppression: a new constructor is added to Throwable
> >>> supports disabling suppression. The existing constructors of
> >> Throwable
> >>> always enable suppression and addSuppressed(null) now always throws
> >>> NullPointerException. A few exception and error types in the
> >>> are allowed by behave as if their objects were created with
> >> suppression
> >>> disabled.
> >>> The fix was recently pushed  and will appear in a future JDK 7
> >> build.
> >>> -Joe
> >> Reading the corresponding javadoc,
> >> I've found that the constructor is protected. In my opinon, it
> >> be public. All the other constructors are public, you can
> >> a Throwable but if you want a Throwable that don't store
> >> suppressed exceptions, you have to subclass it.
> >> I don't understand the rational of this decision.
> > This makes it non trivial to ignore suppressed exceptions - which is
> (IMHO) a
> > good thing. If you have extraordinary circumstances where it is
> necessary to
> > ignore suppressed exceptions (such as VM Out of memory) then this
> > will not be onerous. If it is onerous, then probably you should not be
> trying to
> > ignore supressed exceptions.
> It's not that extraordinary if you write language runtimes :)
> I use to use exceptions to jump back in the control flow when by
> example you jump from a compiled code (in bytecode) back to
> the interpreter (of the language).
> In that case, I don't want to create a subclass if I can create a
> once and reuse it.
> But if I want to be able to reuse it, it should not be able to collect
> suppressed exceptions.
> > Do you have a use case that justifies ignoring supressed exceptions
> for an
> > existing subclass of Throwable that cannot be simply subclassed in
> order to
> > achieve ignoring suppressed exceptions?
> see above.
> But anyway, the real question is why I can't create a Thowable that
> doesn't collect
> suppressed exceptions. Is Throwable a second order citizen ?
Yes in a way it is second order. If it is a Throwable (rather than a subclass)
then you are saying it is not an Error, and it is not an Exception, and it is
not a RuntimeException! So what is it?
Maybe there should be some new top level form of Throwable for these reusable
flow control situations which we both have. maybe a checked form, and an
unchecked form of it? Those two could then be made to do the right thing,
possibly even not having a stacktrace! If it was checked tho' I'd want to
subclass it so that my throws clauses used my own name, not
'ReusableFlowControlException' or whatever it might be called.
> > Bruce
More information about the coin-dev