Skip to content

Latest commit

 

History

History
71 lines (55 loc) · 1.6 KB

File metadata and controls

71 lines (55 loc) · 1.6 KB

error

  • expected[meta header]
  • function[meta id-type]
  • std[meta namespace]
  • bad_expected_access[meta class]
  • cpp23[meta cpp]
constexpr const E& error() const & noexcept;   // (1)
constexpr E& error() & noexcept;               // (2)
constexpr const E&& error() const && noexcept; // (3)
constexpr E&& error() && noexcept;             // (4)

概要

エラー値を取得する。

戻り値

動作説明用のメンバ変数として、エラー値を保持するunexを導入する。

例外

投げない

#include <cassert>
#include <expected>
#include <iostream>
#include <string>

int main()
{
  std::expected<int, std::string> v = std::unexpected{"ERR"};
  try {
    std::cout << v.value() << std::endl;
  } catch (const std::bad_expected_access<std::string>& ex) {
    std::cout << "throw:" << ex.error() << std::endl;
  }
}
  • error()[color ff0000]
  • value()[link ../expected/value.md]
  • std::unexpected[link ../unexpected.md]
  • std::bad_expected_access[link ../bad_expected_access.md]

出力

throw:ERR

バージョン

言語

  • C++23

処理系

参照