Esempio
public static class
ClassA
implements
Iterator {
//Altri metodi Iterator...
public
Object next () {
try
{
//...
}
catch
( Exception e ) {
// Handle exceptions here
}
}
}
Soluzione
Riconsiderare l'uso della clausola catch. Verificare che java.util.NoSuchElementException sia emessa sull'errore.
public static class
ClassA
implements
Iterator {
//Altri metodi Iterator...
public
Object next() {
try
{
//...
}
catch
( Exception e ) {
throw new NoSuchElementException();
}
}
return nextObj;
}