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

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

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

履歴 編集

class
<stdexcept>

std::invalid_argument

std::例

namespace std {
  class invalid_argument : public logic_error;
}

概要

関数などにおいて、引数に渡した値が不正であることを示す例外およびその基底クラスである。 この例外は、std::bitset::bitsetおよびstd::stoiやstd::stof系の関数によって送出される。

メンバ関数

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

#include <string>
#include <stdexcept>
#include <iostream>

int parse_positive_integer(const std::string& s) {
  int value = std::stoi(s);
  if (value <= 0) {
    throw std::invalid_argument("value must be positive");
  }
  return value;
}

int main() {
  try {
    parse_positive_integer("-10");
  } catch (const std::invalid_argument& e) {
    std::cerr << e.what() << "\n";
  }
}

出力例(標準エラー出力)

value must be positive

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.