• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <expected>

    std::bad_expected_access::what

    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;
      }
    }
    

    出力例

    bad access to std::expected without expected value
    

    バージョン

    言語

    • C++23

    処理系

    参照