我正在构建一个双端队列,我只是在发生异常时向用户发送消息。所以,我在尝试从空列表中删除时使用了一个异常:
ArrayDeque 类:
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);
}
在 main 上调用函数:
try{
deque->deleteFront();
}catch(logic_error e){
cout<<e.what();
}
输出是:在抛出 'std::logic_error*' 的实例后调用终止
当我尝试从我的空数组中删除时。我包括了标准异常。
我如何才能返回消息:“您无法从空列表中删除”