I'm relatively new to C++ and I am just wondering, what are the main differences between just throwing an exception or writing std::cerr and exit()? I know that if a exception isn't caught the program will exit. Are there any use cases for std::cerr or should I always throw exceptions? Or should I never use std::cerr in general? Are there some best practices for this?
throw std::runtime_error("runtime error msg"); OR
std::cerr << "cerr error msg"; exit(1); Are both versions OK?
exit()shouldn't be called].std::cerr" for this question, and move the other to a new question. (Since there is an answer already, you should keep the question that matches it.) If you do not see why the questions are independent, consider the codestd::cerr << "cerr error msg"; throw std::runtime_error("runtime error msg");.