title: getline() throws basic_ios::clear exception after reading the last line
body: <p>I am writing a unit test for file read using qtestlib, C++ (clang LLVM version 8.0). I have the following code for reading a file line by line.</p>
  
  <pre><code>std::ifstream infile;
  
  try {
      infile.open(path.c_str());
      std::ios_base::iostate exceptionMask = infile.exceptions() | std::ios::failbit;
      infile.exceptions(exceptionMask);
  
  } catch (std::ios_base::failure&amp; e) {
      // print the exception
      qDebug() &lt;&lt; "Exception caught: " &lt;&lt; QString::fromStdString(e.what());
  }
  
  try {
      std::string line;
      while (std::getline(infile, line)) {
          // print the line
          qDebug() &lt;&lt; QString::fromStdString(line);
      }
  
  } catch (std::ios_base::failure&amp; e) {
      qDebug() &lt;&lt; "Exception caught: " &lt;&lt; QString::fromStdString(e.what());
  }
  </code></pre>
  
  <p><strong>The issue</strong>:</p>
  
  <p>The above code reads all the lines in the file and prints it. But after printing the last line, it throws an exception and prints the following,</p>
  
  <blockquote>
    <p>Exception caught: "basic_ios::clear"</p>
  </blockquote>
  
  <p>I followed many threads, but could not find the solution to this. Why am I getting this error?</p>