分享方式:


domain_error 類別

類別可作為擲回之所有例外狀況的基類,以報告定義域錯誤(如數學而非網路)。

語法

class domain_error : public logic_error {
public:
    explicit domain_error(const string& message);

    explicit domain_error(const char *message);

};

備註

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

domain_error 不會由 Microsoft 實作 C++ 標準程式庫中的任何函式擲回,但可能會由協力廠商程式庫或使用者程式碼擲回。

範例

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

int main()
{
   try
   {
      throw domain_error("Your domain is in error!");
   }
   catch (const exception& e)
   {
      cerr << "Caught: " << e.what() << endl;
      cerr << "Type: " << typeid(e).name() << endl;
   }
}
/* Output:
Caught: Your domain is in error!
Type: class std::domain_error
*/

需求

Header: < stdexcept>

命名空間:std

另請參閱

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