GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::overflow_error - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. stdexcept
  3. overflow_error

最終更新日時: 2026年09月08日 15時55分33秒 (JST)
Akira Takahashi が更新

履歴 編集

class
<stdexcept>

std::overflow_error

namespace std {
  class overflow_error : public runtime_error;
}

概要

overflow_errorクラスは、算術演算の結果がオーバーフロー(扱える値の上限を超過)したことを通知するために送出される例外クラスである。

標準ライブラリでは、std::bitsetのto_ulong()やto_ullong()が、値を戻り値の型で表現できない場合にこの例外を送出する。

このクラスはruntime_errorを公開継承しており、runtime_errorとして捕捉できる。

メンバ関数

名前 説明 対応バージョン
(constructor) コンストラクタ
(destructor) デストラクタ
operator= 代入演算子
what エラー理由を取得する(std::exceptionから継承)

例

#include <stdexcept>
#include <iostream>
#include <bitset>

int main()
{
  std::bitset<128> bits;
  bits.set(127);

  try {
    // 128ビットの値はunsigned longでは表現できない
    unsigned long value = bits.to_ulong();
    std::cout << value << std::endl;
  }
  catch (const std::overflow_error& e) {
    std::cout << "overflow_error: " << e.what() << std::endl;
  }
}

出力例

overflow_error: _Base_bitset::_M_do_to_ulong

例外オブジェクトが保持するメッセージの内容は、処理系によって異なる。

関連項目

  • <stdexcept>
  • std::exception

参照

  • P3378R2 constexpr exception types
    • C++26でconstexpr対応した
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.