G
Guest
What I can do in the following code, to work correct?
I want, when a key does not exist, to throw an Exception instead of
return null.
Solution like "rename method get to get2" is not approved.
public class Hashtable2 extends Hashtable {
public Object get(Object key) throws Exception {
if (super.containsKey(key)) return super.get(key);
throw new Exception("this Hashtable does not contain key: " + key);
}
}
The problem is that:
Hashtable.get has no throws in it declaration, so Hashtable2.get cannot
have too.
Any ideas?
Thanks a lot for your time.
I want, when a key does not exist, to throw an Exception instead of
return null.
Solution like "rename method get to get2" is not approved.
public class Hashtable2 extends Hashtable {
public Object get(Object key) throws Exception {
if (super.containsKey(key)) return super.get(key);
throw new Exception("this Hashtable does not contain key: " + key);
}
}
The problem is that:
Hashtable.get has no throws in it declaration, so Hashtable2.get cannot
have too.
Any ideas?
Thanks a lot for your time.