std::filesystem::filesystem_error:: what
From cppreference.net
<
cpp
|
filesystem
|
filesystem error
C++
filesystem_error
| Member functions | ||||
|
filesystem_error::what
|
||||
| Inherited from std::system_error | ||||
|
const
char
*
what
(
)
const
noexcept
override
;
|
(C++17 이후) | |
설명 바이트 문자열을 반환합니다. 이 설명 문자열은 생성 시 전달된 설명 문자열을 포함합니다. 구현체는 path1() 및 path2() 의 네이티브 형식 경로명과 std::system_error::what() 문자열도 반환된 문자열 내에 포함하도록 권장됩니다.
매개변수
(없음)
반환값
생성 시 전달된 설명 문자열을 포함하는 C-스타일 설명 바이트 문자열입니다.
예제
이 코드 실행
#include <cstdio> #include <filesystem> #include <iostream> #include <string_view> namespace fs = std::filesystem; void explain(std::string_view note, fs::filesystem_error const& ex) { std::cout << note << " exception:\n" << "what(): " << ex.what() << '\n' << "path1(): " << ex.path1() << ", path2(): " << ex.path2() << "\n\n"; } int main() { try { std::filesystem::rename("/dev", "/null"); } catch(fs::filesystem_error const& ex) { explain("fs::rename()", ex); } for (auto const path : {"/bool", "/bin/cat", "/bin/mouse"}) try { std::filesystem::create_directory(path); } catch(fs::filesystem_error const& ex) { explain("fs::create_directory()", ex); } }
가능한 출력:
fs::rename() exception: what(): filesystem error: cannot rename: Permission denied [/dev] [/null] path1(): "/dev", path2(): "/null" fs::create_directory() exception: what(): filesystem error: cannot create directory: Permission denied [/bool] path1(): "/bool", path2(): "" fs::create_directory() exception: what(): filesystem error: cannot create directory: File exists [/bin/cat] path1(): "/bin/cat", path2(): "" fs::create_directory() exception: what(): filesystem error: cannot create directory: Read-only file system [/bin/mouse] path1(): "/bin/mouse", path2(): ""