- filesystem[meta header]
- std::filesystem[meta namespace]
- filesystem_error[meta class]
- function[meta id-type]
- cpp17[meta cpp]
const char* what() const noexcept override;
エラー理由の文字列を取得する。
コンストラクタで設定されたエラー理由を含む未規定のフォーマットの実装定義の文字列を返す。
実装は、system_error
::what()
で返される文字列とネイティブ形式のpath1
とpath2
を含める必要がある。
#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
try {
throw fs::filesystem_error(
"can't copy file. source file doesn't found",
std::make_error_code(std::errc::no_such_file_or_directory)
);
}
catch (fs::filesystem_error& err) {
std::cout << err.what() << std::endl;
}
}
- what()[color ff0000]
- std::make_error_code[link /reference/system_error/make_error_code.md]
- std::errc::no_such_file_or_directory[link /reference/system_error/errc.md]
filesystem error: can't copy file. source file doesn't found: No such file or directory
- C++17
- Clang:
- GCC: 8.1 [mark verified]
- Visual C++: