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


 
 

Share on Google+Share on Google+

Example to show Hash table exception in java

Advertisement
Here we are describing the use of using exception class in java. This tutorial describes the way to handle Hash table exceptions appropriately in your programs and designs.

Example to show Hash table exception in java

     

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

HashTableException.java


import java.util.*;
import java.util.Hashtable;

import java.util.Enumeration;

public class HashTableException {

  public static void main(String args[]) {
  try {
  Hashtable hashtable = new Hashtable();
  hashtable.put("Girish"new Integer(1));
  hashtable.put("Tewari"new Integer(2));
  
  Integer one = (Integerhashtable.get("One");
  System.out.println("Elements in the Hashtable");

  Enumeration e = hashtable.keys();

  while (e.hasMoreElements()) {
  System.out.println(e.nextElement());
  System.out.println(e.nextElement());
  System.out.println(e.nextElement());
  }
  catch (Exception ex) {
  System.out.println
  (
"Exception generated by hash table is "+ex.getMessage());
  }
  }
}

 

Output of the program

java.util.NoSuchElementException: Hashtable Enumerator

 

Download source code

 

Advertisement

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 24, 2008

Ask Questions?    Discuss: Example to show Hash table exception in java  

Post your Comment


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