次の方法で共有


out_of_range クラス

有効範囲外である引数を報告する完全にスローされたすべての例外の基本クラスとしてクラスを使用できます。

class out_of_range : public logic_error {
public:
    explicit out_of_range(const string& message);
    explicit out_of_range(const char *message);
};

解説

exception クラス によって返される値が メッセージ.データのコピーです。

使用例

// out_of_range.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

using namespace std;

int main() {
// out_of_range
   try {
      string str( "Micro" );
      string rstr( "soft" );
      str.append( rstr, 5, 3 );
      cout << str << endl;
   }
   catch ( exception &e ) {
      cerr << "Caught: " << e.what( ) << endl;
   };
}

出力

Caught: invalid string position

必要条件

ヘッダー: の<stdexcept>

名前空間: std

参照

関連項目

logic_error クラス

C++ 標準ライブラリ内のスレッド セーフ