我写API,所以我的API将从外部模块使用。这里是我想不出用什么断言或java.lang.IllegalArgumentException
断言VS运行时异常
/**
* Adds translation of information to underlying store for particular language
* @param languageId The identifier of the language
* @param translation The translation provided for the specific language
* @throws AssertionError if the provided language id is {@code null} or empty
* or provided translation is {@code null} or empty
*/
public final void addTranslation(String languageId, String translation){
assert !(Strings.isNullOrEmpty(languageId));
assert !(Strings.isNullOrEmpty(translation));
translations.put(languageId, translation);
}
如果我使用运行时异常,我认为这可能会损害其使用该API的应用程序的执行的方法之一。如果我使用断言,那么它会伤害我的API,如果断言标志被禁用。
也试过读取类似的帖子When to use an assertion and when to use an exception。但是,检测哪个案例是我的,这有点令人困惑。
有严格定义的方式,其中使用断言何地使用运行时异常?
[异常Vs的断言]的可能的复制(http://stackoverflow.com/questions/1276308/exception-vs-assertion) – emlai 2015-12-20 10:32:48