次の方法で共有


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() によって返される値は、_Codeに基づいてテストに追加する _Messageのコピーです。 _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 の規則