共用方式為


overflow_error 類別

此類別可做為擲回之所有例外狀況的基底類別,這些例外狀況報告算術溢位。

語法

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

    explicit overflow_error(const char *message);

};

備註

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

範例

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

int main()
{
   try
   {
      bitset<33> b;
      b[32] = 1;
      b[0] = 1;
      unsigned long x = b.to_ulong();
   }
   catch (const exception& e)
   {
      cerr << "Caught: " << e.what() << endl;
      cerr << "Type: " << typeid(e).name() << endl;
   }
}
/* Output:
Caught: bitset overflow
Type: class std::overflow_error
*/

需求

Header: < stdexcept>

命名空間:std

另請參閱

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