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

};

解説

what() によって返される値は message.data() のコピーです。 詳細については、次のトピックを参照してください。 what および data

// out_of_range.cpp
// compile with: /EHsc
#include <exception>
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;

int main()
{
   try
   {
      string str("Micro");
      string rstr("soft");
      str.append(rstr, 5, 3);
      cout << str << endl;
   }
   catch (const exception& e)
   {
      cerr << "Caught: " << e.what() << endl;
      cerr << "Type: " << typeid(e).name() << endl;
   }
}
/* Output:
Caught: invalid string position
Type: class std::out_of_range
*/

必要条件

ヘッダー:<stdexcept>

名前空間: std

関連項目

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