2010-06-18 14 views
0

我有一些功能:意外終止推一個shared_ptr到列表時

void addNormalLine(int id, LineNumber number, Rate smsRate, Rate callRate) { 
list<Account>::iterator iAccounts; 
     findAccount(iAccounts, id); 
     if(iAccounts == listOfAccounts.end()){ 
      throw "AccountDoesNotExist"; 
     } 
if(lineExists(number)){ 
      throw "LineExists"; 
     } else{ 
      iAccounts->increaseNumLines(); 
      shared_ptr<Line> currentLine(new Line(id, number, smsRate, callRate)); //here I have some problems 
      listOfLines.push_back(currentLine); //without these two rows it works, but didn't add lines to my list 
     } 
    } 
Account, Rate, LineNumber - some classes 

但它總是隻添加一個或兩個數字,如果我加3總是終止,而我收到terminated, exit value: 3,我想谷歌它,但沒有找到,應該是什麼意思,預先感謝

+1

這與eclipse無關,而且這裏沒有足夠的信息來回答你的問題。我們需要看到更多的代碼。你應該做的第一件事是通過調試器運行這個程序來查看程序終止的位置,這樣你就可以知道錯誤發生在哪裏,並避免將數百行代碼轉儲到這個問題中(因爲沒有人會閱讀它們)。 – 2010-06-18 14:36:35

+0

@Tyler McHenry:你知道這裏有一個問題,我不能這樣做,我不知道爲什麼,但是在我到達這些行之前我的eclispe終止 – helloWorld 2010-06-18 14:40:43

+1

退出值通常從main()中出來。什麼是異常處理等什麼是定義爲listOfLines – 2010-06-18 14:49:56

回答

0

這是一個不好的做法,使用字符串作爲例外值。使用異常類,至少像std :: runtime_error()或更好地創建一個從它派生的新類。

確保你能捕捉到這種方法拋出的異常。

什麼是findAccount的定義?

+0

我有6個語句addLine,我試過每兩個,它的作品完美,但與第三它失敗 – helloWorld 2010-06-18 15:27:12