示例
public static class
ClassA
implements
Iterator {
//Other Iterator methods...
public
Object next () {
try
{
//...
}
catch
( Exception e ) {
// Handle exceptions here
}
}
}
解决方案
重新考虑 catch 子句的功能。确保在出现错误时抛出 java.util.NoSuchElementException
public static class
ClassA
implements
Iterator {
//Other Iterator methods...
public
Object next() {
try
{
//...
}
catch
( Exception e ) {
throw new NoSuchElementException();
}
}
return nextObj;
}