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::range_error - cpprefjp C++日本語リファレンス

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

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

履歴 編集

class
<stdexcept>

std::range_error

namespace std {
  class range_error : public runtime_error;
}

概要

range_errorクラスは、内部計算の結果が値域 (range) の外になったことを通知するために送出される例外クラスである。

標準ライブラリのコンポーネントがこの例外を送出することはなく、ユーザーが使用できる。

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

メンバ関数

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

例

#include <stdexcept>
#include <iostream>
#include <limits>

// 内部計算の結果が、扱える値の範囲を超えることを通知する
double to_ratio(double numerator, double denominator)
{
  double result = numerator / denominator;
  if (result > std::numeric_limits<double>::max() / 2) {
    throw std::range_error("result is out of the representable range");
  }
  return result;
}

int main()
{
  try {
    to_ratio(1.0, 1e-320);
  }
  catch (const std::range_error& e) {
    std::cout << e.what() << std::endl;
  }
}

出力

result is out of the representable range

関連項目

  • <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.