範例

public static class ClassA implements Iterator {
//其他疊代子方法...
public Object next () {

try {
//...
} catch ( Exception e ) {
// 處理異常狀況
}
}

}


解決方案
請重新決定 catch 子句的功能性。確認錯誤時擲出 java.util.NoSuchElementException


public static class ClassA implements Iterator {
//其他疊代子方法...
public Object next() {

try {
//...
} catch ( Exception e ) {
throw new NoSuchElementException();
}
}
return nextObj;
}