【发布时间】:2013-07-19 14:14:34
【问题描述】:
我有一个可能为空的堆栈。我想检查它是否为空,如果是我想抛出一个StackUnderFlowException:
if(myStack.empty()) {
throw new StackUnderFlowException("Some error message");
}
问题:
- 这样有效吗?我知道您不打算使用 Exceptions 进行流量控制。我不认为我是因为我明确检查堆栈是否为空?
-
我如何导入
StackUnderFlowException类,因为我现在收到此错误:PriceHolder 类型的方法 foo(String) 引用了缺失的类型 StackUnderFlowException
非常感谢。
【问题讨论】:
-
你是说
myStack.empty()吗? -
抱歉...这是
Stacks 中的HashTable。我会从问题中删除HashTable的东西,因为它无关紧要。 -
没有标准的 StackUnderflowException。它可能来自您正在使用的库,但如果您不说是哪个并显示您的代码,我们无法判断。使用的标准例外是
java.util.EmptyStackException
标签: java exception exception-handling stack