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.

Ads

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

 

Advertisements

Share on Google+Share on Google+

Example to show Hash table exception in java

Posted on: October 24, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Example to show Hash table exception in java  

Post your Comment


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

Ads

 

Ads