GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::filesystem::filesystem_error::what(3) C++ Standard Libary std::filesystem::filesystem_error::what(3)

std::filesystem::filesystem_error::what - std::filesystem::filesystem_error::what


const char* what() const noexcept override; (since C++17)


Returns an explanatory byte string. This explanatory string contains the explanatory
string passed at the time of construction. Implementations are encouraged to include
the pathnames of path1() and path2() in native format and the
std::system_error::what() string inside the returned string as well.


(none)


A C-stye explanatory byte string that contains the explanatory string passed at the
time of construction.

// Run this code


#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(): ""

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.