2017-02-23 2 views
-1

Visual Studio에서 작업하는 초급 프로그래머입니다. throw를 호출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; 
} 

내 프로그램이 올바른 값을 던지고 종료하는 대신 충돌을 일으 킵니다. 왜 누군가가 설명 할 수 있습니까?

감사합니다.

+0

는 오류 메시지를받을 수 있나요? – Amber

+0

어디에서 올바른 값을 던져야합니까? Plz 귀하의 프로그램에서 예외를 잡아 std :: exit() –

+2

충돌 == 프로그램 종료 전화. –

답변

-1

사용을 시도하고 대신 catch 블록 : 충돌이 발생했을 때

try { /* */ } catch (const std::exception& e) { /* */ } 
관련 문제