- 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
- Clang: 16.0
- GCC: 12.1
- ICC: ??
- Visual C++: ??