다음을 통해 공유


ios_base::failure

The class failure defines the base class for the types of all objects thrown as exceptions, by functions in the iostreams library, to report errors detected during stream buffer operations.

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
        );
};

설명

The value returned by what() is a copy of _Message, possibly augmented with a test based on _Code. If _Code is not specified, the default value is 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;
   }
}
  

요구 사항

Header: <ios>

네임스페이스: std

참고 항목

참조

ios_base 클래스

system_error 클래스

iostream 프로그래밍

iostreams 규칙