Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
UnimplementedException: bad idea or not?
- From: samizdat@xxxxxxxxxxx (Chris Kelly)
- Subject: UnimplementedException: bad idea or not?
- Date: Sat, 29 Jan 2000 17:18:07 -0800
Is it a bad idea to throw an exception when a feature is not implemented,
but the caller of the method can't tell beforehand whether that method is
implemented?
For the sake of argument, assume you have:
class UnimplementedException extends RuntimeException {
...
}
interface Interface {
int getA();
int getB();
}
You want to use it like this:
Interface i = getAnObjectSomePlace();
System.out.println( "A=" + i.getA() + ", B=" + i.getB() );
And, you have two classes that implement Interface:
class One {
int getA() { return 1; }
int getB() { return 1; }
}
class Two {
int getA() { return 2; }
int getB() { throw new UnimplementedException(); }
}
Is there a better way to do this, such as by returning a numeric code
instead of throwing an exception? You don't want to bail just because
something is unimplemented, you just want to ignore it.
Because, the code above could become:
Interface i = getAnObjectSomePlace();
int A,B;
try {
A = i.getA();
}
catch ( UnimplementedException e ) {
A = -1;
}
try {
B = i.getB();
}
catch ( UnimplementedException e ) {
B = -1;
}
System.out.println( "A=" + A + ", B=" + B );
---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
- Prev by Date: Pls. suggest a free Java Editor / IDE for Win 95/NT
- Next by Date: UnimplementedException: bad idea or not?
- Previous by thread: Doubt in using Java Beans
- Next by thread: UnimplementedException: bad idea or not?
- Index(es):