共用方式為


runtime_error 類別

此類別可做為擲回之所有例外狀況的基底類別,這些例外狀況報告僅當程式執行時假定可偵測的錯誤。

語法

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

    explicit runtime_error(const char *message);

};

備註

what() 回的值是 的 message.data() 複本。 如需詳細資訊,請參閱 whatdata

範例

// 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
*/

需求

Header: < stdexcept>

命名空間:std

另請參閱

exception 類別
C++ 標準程式庫中的執行緒安全