4 ms·
When something happens that violates your assumptions about your own program's behavior, throwing it into a state where it doesn't know what happens next. Kind
by whatshisface 5y ago
When something happens that violates your assumptions about your own program's behavior, throwing it into a state where it doesn't know what happens next. Kind of like a panic.
- foldr 5y agoThis 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.
- kazinator 5y agoSo, CPU exceptions such as a "page not present" TLB fault should not be used to implement virtual memory.
- zozbot234 5y agoA "page not present" fault is actually a great example of a resumable condition, which is not quite the same as an exception in the C++ sense.