Bagikan melalui


kelas overflow_error

Kelas ini berfungsi sebagai kelas dasar untuk semua pengecualian yang dilemparkan untuk melaporkan luapan aritmatika.

Sintaks

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

    explicit overflow_error(const char *message);
};

Keterangan

Nilai yang dikembalikan oleh what() adalah salinan .message.data() Untuk informasi lebih lanjut, lihat what dan data.

Contoh

// 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;
   }
}
Caught: bitset overflow
Type: class std::overflow_error

Persyaratan

Header:<stdexcept>

kumpulan nama XML: std

Lihat juga

runtime_error kelas
Keamanan utas di Pustaka Standar C++