java IllegalStateException和NoTouchElementException之间有什么区别
我想在下面的代码中抛出一个错误
if (!this.isAttached(object.getElementById(Name)))
{
throw new NoSuchElementException(Name);
}
this.clickElement(object.getElementById(Name));
哪一个是最适合抛出的异常:NoSuchElementException
或IllegalStateException
# 1 楼答案
您将从文档中了解更多信息:
在您的情况下,抛出
NoSuchElementException
或IllegalStateException
甚至Exception
的异常并不重要,因为它只抛出一条消息,而不是真正的异常如果您阅读了任何异常的构造函数,您可以理解: