将shared_ptr推送到列表时意外终止

时间:2010-06-18 14:29:59

标签: c++ stl

我有一些功能:

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 个答案:

答案 0 :(得分:0)

将字符串用作异常值是一种不好的做法。使用类来表示异常,至少像std :: runtime_error()或者更好地创建一个从它派生的新类。

确保捕获此方法中的异常。

findAccount的定义是什么?