]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/filesystem/src/exception.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / filesystem / src / exception.cpp
CommitLineData
92f5a8d4
TL
1// boost/filesystem/exception.hpp -----------------------------------------------------//
2
3// Copyright Beman Dawes 2003
4// Copyright Andrey Semashev 2019
5
6// Distributed under the Boost Software License, Version 1.0.
7// See http://www.boost.org/LICENSE_1_0.txt
8
9// Library home page: http://www.boost.org/libs/filesystem
10
20effc67
TL
11#include "platform_config.hpp"
12
92f5a8d4
TL
13#include <string>
14#include <boost/filesystem/config.hpp>
15#include <boost/filesystem/path.hpp>
16#include <boost/filesystem/exception.hpp>
17
18#include "error_handling.hpp"
19
20#include <boost/config/abi_prefix.hpp> // must be the last #include
21
22namespace boost {
23namespace filesystem {
24
25filesystem_error::filesystem_error(const std::string& what_arg, system::error_code ec) :
26 system::system_error(ec, what_arg)
27{
28 try
29 {
30 m_imp_ptr.reset(new impl());
31 }
32 catch (...)
33 {
34 m_imp_ptr.reset();
35 }
36}
37
38filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, system::error_code ec) :
39 system::system_error(ec, what_arg)
40{
41 try
42 {
43 m_imp_ptr.reset(new impl(path1_arg));
44 }
45 catch (...)
46 {
47 m_imp_ptr.reset();
48 }
49}
50
51filesystem_error::filesystem_error(const std::string& what_arg, const path& path1_arg, const path& path2_arg, system::error_code ec) :
52 system::system_error(ec, what_arg)
53{
54 try
55 {
56 m_imp_ptr.reset(new impl(path1_arg, path2_arg));
57 }
58 catch (...)
59 {
60 m_imp_ptr.reset();
61 }
62}
63
64filesystem_error::filesystem_error(filesystem_error const& that) :
65 system::system_error(static_cast< system::system_error const& >(that)),
66 m_imp_ptr(that.m_imp_ptr)
67{
68}
69
70filesystem_error& filesystem_error::operator= (filesystem_error const& that)
71{
72 static_cast< system::system_error& >(*this) = static_cast< system::system_error const& >(that);
73 m_imp_ptr = that.m_imp_ptr;
74 return *this;
75}
76
77filesystem_error::~filesystem_error() BOOST_NOEXCEPT_OR_NOTHROW
78{
79}
80
81const char* filesystem_error::what() const BOOST_NOEXCEPT_OR_NOTHROW
82{
83 if (m_imp_ptr.get()) try
84 {
85 if (m_imp_ptr->m_what.empty())
86 {
87 m_imp_ptr->m_what = system::system_error::what();
88 if (!m_imp_ptr->m_path1.empty())
89 {
90 m_imp_ptr->m_what += ": \"";
91 m_imp_ptr->m_what += m_imp_ptr->m_path1.string();
92 m_imp_ptr->m_what += "\"";
93 }
94 if (!m_imp_ptr->m_path2.empty())
95 {
96 m_imp_ptr->m_what += ", \"";
97 m_imp_ptr->m_what += m_imp_ptr->m_path2.string();
98 m_imp_ptr->m_what += "\"";
99 }
100 }
101
102 return m_imp_ptr->m_what.c_str();
103 }
104 catch (...)
105 {
106 m_imp_ptr->m_what.clear();
107 }
108
109 return system::system_error::what();
110}
111
112const path& filesystem_error::get_empty_path() BOOST_NOEXCEPT
113{
114 static const path empty_path;
115 return empty_path;
116}
117
118// error handling helpers declared in error_handling.hpp -----------------------------------------------------//
119
120void emit_error(err_t error_num, system::error_code* ec, const char* message)
121{
122 if (!ec)
123 BOOST_FILESYSTEM_THROW(filesystem_error(message, system::error_code(error_num, system::system_category())));
124 else
125 ec->assign(error_num, system::system_category());
126}
127
128void emit_error(err_t error_num, const path& p, system::error_code* ec, const char* message)
129{
130 if (!ec)
131 BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category())));
132 else
133 ec->assign(error_num, system::system_category());
134}
135
136void emit_error(err_t error_num, const path& p1, const path& p2, system::error_code* ec, const char* message)
137{
138 if (ec == 0)
139 BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category())));
140 else
141 ec->assign(error_num, system::system_category());
142}
143
144} // namespace filesystem
145} // namespace boost
146
147#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas