I have written a simple application that reads a data file, parses the text and then does some processing on that data. The data file is opened in my main() function. Is it good programming practice to use the exit() function if it is determined that the file was not opened properly? eg:
if (!file.is_open() ){
exit(1);
}
Furthermore, my program has a separate function to parse the data in the file. This function is called by main(). If the function finds an error in the data, I want the program to stop, after printing an error message. In such a situation, is it acceptable to use the exit() function within my parsing function? I am asking this question because, to me, it doesn't seem to be very tidy to allow a function to exit a program on it's own without returning control to the main() function. (I apologize if this question seems pretty obvious.. I'm new to C++ and programming in general).