Skip to content

Latest commit

 

History

History
69 lines (53 loc) · 1.9 KB

File metadata and controls

69 lines (53 loc) · 1.9 KB

runtime_error

  • stdexcept[meta header]
  • std[meta namespace]
  • class[meta id-type]
namespace std {
  class runtime_error : public exception;
}
  • exception[link /reference/exception/exception.md]

概要

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

実行時エラーは、プログラムの制御が及ばない事象に起因するため、あらかじめ予見することが難しいものを指す。

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

メンバ関数

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

#include <stdexcept>
#include <iostream>

void process(bool device_available)
{
  if (!device_available) {
    // 実行時にしか判明しないエラー
    throw std::runtime_error("device is not available");
  }
}

int main()
{
  try {
    process(false);
  }
  catch (const std::runtime_error& e) {
    std::cout << e.what() << std::endl;
  }
}
  • std::runtime_error[color ff0000]

出力

device is not available

関連項目

参照