Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » [Compiler modification] Propagate exception throws from for-each?([Compiler modification] Propagate exception throws from for-each?)
icon4.gif  [Compiler modification] Propagate exception throws from for-each? [message #1451948] Fri, 24 October 2014 14:52
i AqD is currently offline i AqDFriend
Messages: 8
Registered: July 2014
Location: Taipei
Junior Member
Hello JDT devs!

I'm considering adding 'throws' into Iterable and Iterator (hasNext/next), like these:

interface Iterable<E, TException extends Exception> {
    Iterator<E, TException> iterator();
}
...
interface Iterator<E, TException extends Exception> {
    boolean hasNext() throws TException;
    E next() throws TException;
}


I already have overridden interfaces from rt.jar for other purposes (via endorsed dir), and throws generic exceptions is also proved to work flawlessly with Eclipse Luna. So modifying Iterable/Iterator wouldn't be a big deal, and I'm looking at the JDT code of ForeachStatement, as for-each itself doesn't handle throws from next/hasNext by design.

But before I modify it, there is something that I couldn't understand: In ForeachStatement.resolve(), why does it check the length of generic arguments of Iterable below?
    TypeBinding[] arguments = null;
    switch (iterableType.kind()) {
        case Binding.RAW_TYPE : // for(Object o : Iterable)
        ....
    }
    // generic or parameterized case
    if (arguments.length != 1) break checkIterable; // per construction can only be one


Since by definition Iterable<E> has only one generic argument and it's the item type, why bother checking the total length? What does "per construction can only be one" mean? Is there any use or definition of other arguments already? (I intend to add the 2nd to represent throwable exception type, and call handlingContext.checkExceptionHandlers there)

Previous Topic:[RESOLVED]Can't start Luna (eclipse crashes)
Next Topic:Calculator in java language
Goto Forum:
  


Current Time: Fri Nov 27 18:41:16 GMT 2020

Powered by FUDForum. Page generated in 0.02003 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top