runtime_error クラス

このクラスは、プログラムの実行時にのみ検出可能なエラーを通知するためにスローされる例外すべてに対する基底クラスとして機能します。

構文

class runtime_error : public exception {
public:
    explicit runtime_error(const string& message);

    explicit runtime_error(const char *message);

};

解説

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

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

int main()
{
   try
   {
      locale loc("test");
   }
   catch (const exception& e)
   {
      cerr << "Caught: " << e.what() << endl;
      cerr << "Type: " << typeid(e).name() << endl;
   }
}
/* Output:
Caught: bad locale name
Type: class std::runtime_error
*/

必要条件

ヘッダー:<stdexcept>

名前空間: std

関連項目

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