June 2017
Intermediate to advanced
532 pages
12h 59m
English
We have seen that we can enable exceptions per stream object, s, with s.exceptions(s.failbit | s.badbit). This means, that there is no way to use, for example, the std::ifstream instance's constructor for opening a file if we want to get an exception when opening that file is not possible:
ifstream f {"non_existant.txt"};f.exceptions(...); // too late for an exception
This is a pity because exceptions actually promise that they make error handling less clumsy compared to old-school C-style code, which is riddled with loads of if branches, which handle errors after every step.
If we played around trying to provoke various reasons for streams to fail, we would realize that there are no different exceptions being thrown. This ...
Read now
Unlock full access