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 = (Integer) hashtable.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