分享方式:


invalid_argument 類別

此類別可做為擲回之所有例外狀況的基底類別,這些例外狀況報告無效的引數。

語法

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

    explicit invalid_argument(const char *message);

};

備註

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

範例

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

int main()
{
   try
   {
      bitset<32> b("11001010101100001b100101010110000");
   }
   catch (const exception& e)
   {
      cerr << "Caught: " << e.what() << endl;
      cerr << "Type: " << typeid(e).name() << endl;
   }
}
/* Output:
Caught: invalid bitset char
Type: class std::invalid_argument
*/

需求

Header: < stdexcept>

命名空間:std

另請參閱

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