https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71950
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- This isn't easy to do. The exception is thrown in basic_ios::clear() when setting the error flags, but the cause of the error is not known there. We could look at errno, but not all such errors are caused by C library functions that set errno, so it would be misleading in many cases.