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

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

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

履歴 編集

class
<stdexcept>

std::logic_error

namespace std {
  class logic_error : public exception;
}

概要

logic_errorクラスはプログラムの実行前に検出可能なエラー(論理エラー)を通知するために送出される例外クラス全般に対する基底クラスである。

メンバ関数

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

例

#include <stdexcept>
#include <iostream>

int square_root(int num) {
  if (num < 0) {
    throw std::invalid_argument("Cannot perform calculations with negative numbers!");
  }
  return num * num;
}

int main() {
  try {
    square_root(-5);
  } catch (const std::logic_error& e) {
    std::cerr << "Error: " << e.what() << "\n";
  }
}

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

Error: Cannot perform calculations with negative numbers!

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.