1 // boost/filesystem/exception.hpp -----------------------------------------------------//
3 // Copyright Beman Dawes 2003
4 // Copyright Andrey Semashev 2019
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
9 // Library home page: http://www.boost.org/libs/filesystem
12 #include <boost/filesystem/config.hpp>
13 #include <boost/filesystem/path.hpp>
14 #include <boost/filesystem/exception.hpp>
16 #include "error_handling.hpp"
18 #include <boost/config/abi_prefix.hpp> // must be the last #include
21 namespace filesystem {
23 filesystem_error::filesystem_error(const std::string& what_arg, system::error_code ec) :
24 system::system_error(ec, what_arg)
28 m_imp_ptr.reset(new impl());
36 filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, system::error_code ec) :
37 system::system_error(ec, what_arg)
41 m_imp_ptr.reset(new impl(path1_arg));
49 filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, const path& path2_arg, system::error_code ec) :
50 system::system_error(ec, what_arg)
54 m_imp_ptr.reset(new impl(path1_arg, path2_arg));
62 filesystem_error::filesystem_error(filesystem_error const& that) :
63 system::system_error(static_cast< system::system_error const& >(that)),
64 m_imp_ptr(that.m_imp_ptr)
68 filesystem_error& filesystem_error::operator= (filesystem_error const& that)
70 static_cast< system::system_error& >(*this) = static_cast< system::system_error const& >(that);
71 m_imp_ptr = that.m_imp_ptr;
75 filesystem_error::~filesystem_error() BOOST_NOEXCEPT_OR_NOTHROW
79 const char* filesystem_error::what() const BOOST_NOEXCEPT_OR_NOTHROW
81 if (m_imp_ptr.get()) try
83 if (m_imp_ptr->m_what.empty())
85 m_imp_ptr->m_what = system::system_error::what();
86 if (!m_imp_ptr->m_path1.empty())
88 m_imp_ptr->m_what += ": \"";
89 m_imp_ptr->m_what += m_imp_ptr->m_path1.string();
90 m_imp_ptr->m_what += "\"";
92 if (!m_imp_ptr->m_path2.empty())
94 m_imp_ptr->m_what += ", \"";
95 m_imp_ptr->m_what += m_imp_ptr->m_path2.string();
96 m_imp_ptr->m_what += "\"";
100 return m_imp_ptr->m_what.c_str();
104 m_imp_ptr->m_what.clear();
107 return system::system_error::what();
110 const path& filesystem_error::get_empty_path() BOOST_NOEXCEPT
112 static const path empty_path;
116 // error handling helpers declared in error_handling.hpp -----------------------------------------------------//
118 void emit_error(err_t error_num, system::error_code* ec, const char* message)
121 BOOST_FILESYSTEM_THROW(filesystem_error(message, system::error_code(error_num, system::system_category())));
123 ec->assign(error_num, system::system_category());
126 void emit_error(err_t error_num, const path& p, system::error_code* ec, const char* message)
129 BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category())));
131 ec->assign(error_num, system::system_category());
134 void emit_error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message)
137 BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category())));
139 ec->assign(error_num, system::system_category());
142 } // namespace filesystem
145 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas