https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71950
--- Comment #4 from Austin Kramer <skaianhero at gmail dot com> --- (In reply to Jonathan Wakely from comment #3) > > That would add overhead for exception handling and the vast majority of > users do not use exceptions with fstream. > That overhead would be almost nothing compared to the disk-accessing I/O that happens deeper under the hood of these functions. It would simply involve changing fstream::open to something like this (existing syntax tweaked to make it easier to fit here): void open(const char* __s, ios_base::openmode __mode) { if (!_M_filebuf.open(__s, __mode)) this->setstate(ios_base::failbit); else try { this->clear(); } catch (const std::ios::failure &ex) { char buf[ESTR_BUF_SZ]; strerror_r(errno, buf, sizeof(buf)); throw std::ios::failure(buf); } } I don't condone magic-mumber-sized buffers, and this is an errno example (that DOES work on my playform), But my point is that the overhead happens only in the failure case, after the comparatively expensive main-sequence operation, with hardly any frame state that needs saving, and it only does any actual throwing or buffer-writing if clear() is set up to throw. So it should be pretty negligible. > > Users can specialize basic_filebuf so we can't rely on non-standard > functions. > > I don't think it's worth changing anything here. I wouldn't be so sure. Non-standard functionality aside, I still think the exception message ought to be changed. I agree that checking the status bits of the stream is the conventional way to go, but for some callers, that just ISN'T ENOUGH INFORMATION. Most file operations can fail for more than one reason, and having at least the ABILITY to generate a user or developer-readable error message from standard library functions can be important in some cases. Because between this vague message and PR 66145 preventing a valid system_error containing exception from getting generated, there is NO way to determine why an fstream function failed. And NOBODY likes seeing "Unknown Error".