Поделиться через


ios_base::failure

Класс failure определяет базовый класс для всех типов объектов брошенных в виде исключений, функциями в библиотеке iostreams, чтобы уведомить ошибки, выявленные в ходе операций буфера потока.

namespace std {
    class failure : public system_error {
    public:
        explicit failure(
            const string& _Message, 
            const error_code& _Code = io_errc::stream
        );
        explicit failure(
            const char* _Str, 
            const error_code& _Code = io_errc::stream
        );
};

Заметки

Значение, возвращаемое what() копию _Message, возможно, тест увеличенное на основе _Code. Если _Code не указано, значение по умолчанию make_error_code(io_errc::stream).

Пример

// ios_base_failure.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>

int main ( ) 
{
   using namespace std;
   fstream file;
   file.exceptions(ios::failbit);
   try 
   {
      file.open( "rm.txt", ios_base::in );
      // Opens nonexistent file for reading
   }
   catch( ios_base::failure f ) 
   {
      cout << "Caught an exception: " << f.what() << endl;
   }
}
  

Требования

Заголовок:<ios>

Пространство имен: std

См. также

Ссылки

Класс ios_base

Класс system_error

Программирование iostream

Соглашения iostreams