public static class ClassA implements Iterator {
//Other Iterator methods... public Object next () {
try {
//...
} catch ( Exception e ) {
// Handle exceptions here
}
}
}
Lösung
Überdenken Sie die Funktionalität der catch-Klausel. Stellen Sie sicher, dass bei einem Fehler die Ausnahmebedingung 'java.util.NoSuchElementException' ausgelöst wird.
public static class ClassA implements Iterator {
//Other Iterator methods... public Object next() {
try {
//...
} catch ( Exception e ) {
throw new NoSuchElementException();
}
}
return nextObj;
}