-1
这里的初学程序员在Visual Studio中工作。throw导致代码崩溃而不是仅仅退出
vector<string> fileParse(vector<string> & inputStrings, string & fileName) {
ifstream x;
x.open(fileName);
cout << "attempting to open file" << endl;
if (!x.is_open()) {
cout << "Bad input file name. Input was: " << fileName << endl;
throw lab0badInput;
}
else {
string temp;
while (x >> temp) {
inputStrings.push_back(temp);
}
x.close();
}
return inputStrings;
}
调用throw
导致我的程序崩溃,而不是扔正确的值和退出的。有人可以解释为什么吗?
谢谢!
你得到一个错误信息,当崩溃发生? – Amber
应该在哪里抛出正确的值? PLZ在你的程序中捕获你的异常并调用std :: exit() –
Crash ==程序退出。 –