在这种情况下建议使用NullPointerException
:呃争议..这是一个很好的做法吗?
/**
* Drop the database referenced by the singleton.
*
* @throws NullPointerException
*/
public static void dropDatabase() throws NullPointerException {
if (store != null) {
store.dropDatabase(DATABASE);
} else {
throw new NullPointerException("No valid database connection.");
}
}
'IllegalStateException'很合适。 –
+1 for IllegalStateException – Nishant
@Jon Skeet - 指向Guava的不错指针。 – wulfgarpro