3 ms·
This would mean that attempting to open a file that doesn't exist shouldn't throw an exception. But that is exactly what it does in the standard libraries of ma
by foldr 5y ago
This would mean that attempting to open a file that doesn't exist shouldn't throw an exception. But that is exactly what it does in the standard libraries of many languages with exceptions.
- jcelerier 5y agoNot in C++ I believe ?
- foldr 5y agoThe C++ standard IO library doesn't enable exceptions by default, but IIRC that's just a relic of the fact that it dates back to when C++ didn't have exceptions.
- mpyne 5y agoIt's library dependent. iostreams (part of C++ std lib) doesn't throw exceptions by default but I believe it can be configured to throw if you want.
- TheMonarchist 5y agohttps://en.cppreference.com/w/cpp/io/basic_ios/exceptions https://en.cppreference.com/w/cpp/io/basic_ios/exceptions
- jcelerier 5y agoDamn, in all those years I've absolutely never come across this, thanks
- YATA0 5y agoThat is manually throwing an exception if the file doesn't exist. C++ stdlib does not throw an exception if a file does not exist. I agree with this philosophy because files not existing isn't an exceptional case.
- spc476 5y agoIt should be up to the application to throw or not, not a library. I write a system service. If it can't find the configuration file, it can't continue, so it throws an exception. If it can't open a file that contains state from a previous run (maybe because it's the first time it's running) that's fine, the program can run without it and thus, no exception.