Java异常命名约定 [英] Java Exception Naming Conventions
问题描述
在Java中,使用非法(如 IllegalArgumentException
)与无效(如 javax.activity.InvalidActivityException
)?
In Java, is there a semantic difference between using "Illegal" (as in IllegalArgumentException
) versus "Invalid" (as in javax.activity.InvalidActivityException
)?
在作业过程中,编写 IllegalArgumentException
的子类来表示一系列输入字符变得有用这不能被标记,我想知道约定是否使用 InvalidTokenException
或 IllegalTokenException
。
During the course of an assignment it became useful to write a subclass of IllegalArgumentException
to represent a series of input characters that cannot be tokenized, and I'm wondering whether convention says to use InvalidTokenException
or IllegalTokenException
.
到目前为止,我唯一的区别是, java.lang
似乎更喜欢非法,而code> javax。* prefersInvalid。但是,还有 java.security.InvalidParameterException
,它是 IllegalArgumentException
的子类。
The only difference I can find so far is that java.lang
seems to prefer "Illegal" while javax.*
prefers "Invalid". However, there is also java.security.InvalidParameterException
which is a subclass of IllegalArgumentException
.
推荐答案
您可以拥有API的合法使用,并且仍然具有无效数据;这是所有语义。
You can have legal usage of an API and still have invalid data; it is all semantics.
这篇关于Java异常命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!