我寫一個C++代碼,O節點添加到列表中我想拋出的錯誤,當一個節點已經結束存在,它是工作,但每當我已經退出節點調用它,我得到這個錯誤。任何人都知道原因以及它是如何修復的?C++拋出錯誤
異常終止 後叫做拋出 '錯誤'
中止
List& List::addnode(node p){
node *Current=NULL;
p.nextNode = NULL;
p.previousNode = NULL;
if (!firstNode) firstNode = &p;
else Current = firstNode;
while (Current){
if ((*Current) == p){
throw NodeExist;
return *this;
}
if (!(Current->nextNode)){
Current->nextNode = &p;
p.previousNode = Current;
return *this;
}
Current = Current->nextNode;
}
}
編輯的一個實例:我把它像
try{
x.addNode(p);
x.addNode(p1);
x.addNode(p2);
x.addNode(p1);
x.addNode(p4);
}
catch(int i){
cout<<i<<endl;
}
如果我抹去的一個x.addNode(p1);
線路正常工作無異常...
節點是否也在這裏通過值傳遞,所以你得到一個副本? – ColWhi 2011-05-01 09:03:04
你可以顯示'Error'和'NodeExist'的定義嗎? – 2011-05-01 09:23:41