在 Arraydeque 中设置异常不会停止执行
Making exceptions in Arraydeque don't stop the execution
我正在构建一个Deque,我只是在发生异常时何时向用户发送消息。因此,我在尝试从空列表中删除时使用异常:
ArrayDequeClass:
void ArrayDeque::deleteFront(){
//Just check if list it's empty. If it is, it throw the exception.
if(isEmpty())throw new logic_error("You can't delete from an empty
list");
data.erase(data.begin()+front);
}
在主节点上调用函数:
try{
deque->deleteFront();
}catch(logic_error e){
cout<<e.what();
}
输出为:在抛出"std::logic_error*"实例后调用终止
当我尝试从空数组中删除时。我包括stdexcept。
我怎么能只返回消息:"您无法从空中删除 列表">
你正在抛出一个带有throw new
的指针。这与期望按值生成对象的 catch 子句不匹配。
只需删除new
即可。(并可选择通过常量引用捕获(。
相关文章:
- Firebase C++VS2018 SDL2-在Firebase::app::create(..)上执行异常处理
- 捕获异常后如何退出程序执行
- 如何处理libstdc++跨执行边界抛出的异常
- 主函数执行时C++堆栈溢出异常
- 英特尔 Pin:RECEIVED_ACCESS_FAULT异常后正确继续执行
- PAGE_GUARD,VirtualProtect不会在执行访问时引发异常
- 执行视觉工作室异常处理模式
- C++执行期间的类成员函数错误/异常处理
- 在 Arraydeque 中设置异常不会停止执行
- 我在执行 levelOrder 函数时无法弄清楚异常终止的原因?
- 通过引用派生类对象从基类对象执行向下转换时引发bad_cast异常
- 捕获块调试语句在引发异常后未执行
- G++ 和 CL(VS2017) 都编译成功,但 cl 编译的可执行文件运行异常
- 在机器异常之后重新执行程序
- 异常的奇怪行为(执行了一些未调用的方法)
- 自定义异常并不总是执行 what()
- 在std::for_each的执行过程中累积结果,该异常被中断
- 在堆栈中执行 POP 时在下溢中进行异常处理
- 给定范围内的完美平方:循环执行异常
- 当我们不给 C 可执行程序参数时如何处理异常