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

  1. リファレンス
  2. exception
  3. exception

最終更新日時: 2025年04月03日 16時03分23秒 (JST)
Akira Takahashi が更新

履歴 編集

class
<exception>

std::exception

namespace std {
  class exception;
}

概要

exceptionクラスは、標準ライブラリが提供する全ての例外クラスの基底クラスである。

標準ライブラリによって送出される例外オブジェクトのクラスは全て、このクラスから派生する。したがって、標準の例外は全てこのクラスで捕捉できる。

メンバ関数

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

例

#include <iostream>
#include <exception>
#include <stdexcept> // std::runtime_error

int main()
{
  try {
    bool is_error = true;
    if (is_error) { // なんらかのエラーが発生した
      throw std::runtime_error("error!"); // 例外送出
    }
  }
  catch (std::exception& e) {
    // 例外を捕捉
    // エラー理由を出力する
    std::cout << e.what() << std::endl;
  }
}

出力

error!

参照

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