Post by Christopher J. PiszPost by Ãö TiibThat example does not compile as C++. Top level try?
#include <sstream>
#include <boost/filesystem.hpp>
//--------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
try
{
// Creates all directories in the path if they do not exist
boost::filesystem::create_directories("!?#Gibberish!?#");
}
catch(boost::filesystem::filesystem_error & e)
{
// Not very clear on how to get meaningful information from
the exception
// The codes are found in boost::system::errc::<your code here>
// Try and get the value and then find the Windows codes
mapped to the boost codes?
// The actual numeric value can be found in the header with
the Windows codes - errno.h under _CRT_NO_POSIX_ERROR_CODES?
//
// You'll have to compare against specific ones and make your
own meaningful error message?
const boost::system::error_code errorCode = e.code();
std::ostringstream msg;
msg << "boost::filesystem::create_directories failed with
error code: " << errorCode.message();
// Use our own exception type
throw std::runtime_error(msg.str());
}
return 0;
}
Post by Ãö Tiibhttp://www.boost.org/doc/libs/1_61_0/libs/system/doc/reference.html#Header-error_code
That's what I thought looking through the header, but "no socket option"
makes no sense.
It appears to be these codes
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681381(v=vs.85).aspx
but I want to make sure. IT doesn't mention it in the docs at all.
Yep, it seems weakly documented so I started to wonder why it works
in my projects as platform agnostic. :D Appears that it depends on error
category and different error codes of different categories may be
converted or may compare equal. My bots found such mock/hacking tool
from internet somewhere:
#include <iostream>
#include <boost/asio/error.hpp>
#include <boost/filesystem.hpp>
#include <boost/system/error_code.hpp>
int main()
{
// Two different error codes.
boost::system::error_code code1 = make_error_code(
boost::system::errc::no_such_file_or_directory);
boost::system::error_code code2 = make_error_code(
boost::asio::error::host_not_found_try_again);
// That have different error categories.
assert(code1.category() != code2.category());
assert(code1.default_error_condition().category() !=
code2.default_error_condition().category());
// Yet have the same value.
assert(code1.value() == code2.value());
assert(code1.default_error_condition().value() ==
code2.default_error_condition().value());
// Use the comparision operation to check both value
// and category.
assert(code1 != code2);
assert(code1.default_error_condition() !=
code2.default_error_condition());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Test with Boost.Filesytem
try
{
boost::filesystem::canonical("bogus_file");
}
catch(boost::filesystem::filesystem_error& error)
{
if (error.code() ==
make_error_code(boost::system::errc::no_such_file_or_directory))
{
std::cout << "No file or directory" << std::endl;
}
if (error.code() ==
make_error_code(boost::asio::error::host_not_found_try_again))
{
std::cout << "Host not found" << std::endl;
}
}
}