Skip to content

Latest commit

 

History

History
64 lines (49 loc) · 1.21 KB

File metadata and controls

64 lines (49 loc) · 1.21 KB

what

  • expected[meta header]
  • function[meta id-type]
  • std[meta namespace]
  • bad_expected_access[meta class]
  • cpp23[meta cpp]
const char* what() const noexcept override;

概要

エラー理由の文字列を取得する。

戻り値

エラー理由となる実装定義の文字列

例外

投げない

#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 << ex.what() << std::endl;
  }
}
  • what()[color ff0000]
  • value()[link ../expected/value.md]
  • std::unexpected[link ../unexpected.md]
  • std::bad_expected_access[link ../bad_expected_access.md]

出力例

bad access to std::expected without expected value

バージョン

言語

  • C++23

処理系

参照