Home Java Java-exception Example to show Iterator exception in java
Questions:Ask|Latest



Example to show Iterator exception in java
Posted on: October 24, 2008 By Deepak Kumar
Here we are describing the use of using exception class in java .This tutorial describes the way to handle Iterator exceptions appropriately in your programs and designs.

Example to show Iterator exception in java

     

Here we are describing the use of using exception class in java .This tutorial describes the way to handle Iterator exceptions appropriately in your programs and designs. The steps involved in the program are described below:-

IteratorException.java


import java.util.*;

public class IteratorException {

  public static void main(String[] args) {
  try {
  ArrayList List = new ArrayList();
  List.add("1");
  List.add("2");
  List.add("3");
  List.remove("34");

  Iterator itr = List.iterator();
  while (itr.hasNext()) {
  System.out.println(itr.next());
  }
  System.out.println(itr.next());
  catch (Exception ex) {
  System.out.println(ex);
  }
  }
}

 

Output of the program

1
2
3
java.util.NoSuchElementException


Download source code

 


Recommend the tutorial

Ask Questions?    Discuss: Example to show Iterator exception in java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments