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

履歴 編集

function
<filesystem>

std::filesystem::filesystem_error::what(C++17)

const char* what() const noexcept override;

概要

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

戻り値

コンストラクタで設定されたエラー理由を含む未規定のフォーマットの実装定義の文字列を返す。

実装は、system_error::what()で返される文字列とネイティブ形式のpath1path2を含める必要がある。

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

出力例

filesystem error: can't copy file. source file doesn't found: No such file or directory

バージョン

言語

  • C++17

処理系

参照