Skip to content

Latest commit

 

History

History
68 lines (55 loc) · 1.95 KB

filesystem_error.md

File metadata and controls

68 lines (55 loc) · 1.95 KB

filesystem_error

  • filesystem[meta header]
  • std::filesystem[meta namespace]
  • class[meta id-type]
  • cpp17[meta cpp]
namespace std::filesystem {
  class filesystem_error : public system_error;
}
  • system_error[link /reference/system_error/system_error.md]

概要

filesystem_errorクラスは、ファイルシステムの操作で発生したエラーを扱う例外クラスである。

メンバ関数

名前 説明 対応バージョン
(constructor) コンストラクタ C++17
~filesystem_error() = default デストラクタ C++17
filesystem_error& operator=(const filesystem_error&) = default 代入演算子 C++17
path1 エラーとなったひとつめのパスを取得する C++17
path2 エラーとなったふたつめのパスを取得する C++17
code エラーコードを取得する C++17
what エラー理由の文字列を取得する C++17

#include <iostream>
#include <cassert>
#include <filesystem>

namespace fs = std::filesystem;

int main()
{
  assert(!fs::exists("a/from.txt"));

  // 存在しないファイルをコピーしようとした
  try {
    fs::copy_file("a/from.txt", "b/to.txt");
  }
  catch (fs::filesystem_error& err) {
    std::cout << err.what() << std::endl;
  }
}
  • fs::filesystem_error[color ff0000]
  • fs::exists[link /reference/filesystem/exists.md]
  • fs::copy_file[link /reference/filesystem/copy_file.md]

出力例

filesystem error: cannot copy file: No such file or directory [a/from.txt] [b/to.txt]

バージョン

言語

  • C++17

処理系