<分区>
我正在构建一个双端队列,我只是在发生异常时向用户发送消息。因此,我使用异常尝试从空列表中删除:
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。
我如何才能返回消息:“你不能从空的中删除 列表”