I have this code and just wondered why it's not throwing an exception (or in which case it should do).
From cplusplus.com :
If the function fails to open a file, the failbit state flag is set for the stream (which may throw ios_base::failure if that state flag was registered using member exceptions).
#include <fstream>
#include <exception>
#include <iostream>
int main() {
std::ofstream fs;
try {
fs.open("/non-existing-root-file");
} catch (const std::ios_base::failure& e) {
std::cout << e.what() << std::endl;
}
if (fs.is_open())
std::cout << "is open" << std::endl;
else
std::cout << "is not open" << std::endl;
return 0;
}