aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/boost/filesystem/src/exception.cpp
blob: 0b92c0d9c1e9821f1355993168cb36dfc0f2f474 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//  boost/filesystem/exception.hpp  -----------------------------------------------------//

//  Copyright Beman Dawes 2003
//  Copyright Andrey Semashev 2019

//  Distributed under the Boost Software License, Version 1.0.
//  See http://www.boost.org/LICENSE_1_0.txt

//  Library home page: http://www.boost.org/libs/filesystem

#include "platform_config.hpp"

#include <string>
#include <boost/system/error_code.hpp>
#include <boost/system/system_category.hpp>
#include <boost/filesystem/config.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/exception.hpp>

#include "error_handling.hpp"

#include <boost/filesystem/detail/header.hpp> // must be the last #include

namespace boost {
namespace filesystem {

BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const char* what_arg, system::error_code ec) :
    system::system_error(ec, what_arg)
{
    try
    {
        m_imp_ptr.reset(new impl());
    }
    catch (...)
    {
        m_imp_ptr.reset();
    }
}

BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(std::string const& what_arg, system::error_code ec) :
    system::system_error(ec, what_arg)
{
    try
    {
        m_imp_ptr.reset(new impl());
    }
    catch (...)
    {
        m_imp_ptr.reset();
    }
}

BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const char* what_arg, path const& path1_arg, system::error_code ec) :
    system::system_error(ec, what_arg)
{
    try
    {
        m_imp_ptr.reset(new impl(path1_arg));
    }
    catch (...)
    {
        m_imp_ptr.reset();
    }
}

BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(std::string const& what_arg, path const& path1_arg, system::error_code ec) :
    system::system_error(ec, what_arg)
{
    try
    {
        m_imp_ptr.reset(new impl(path1_arg));
    }
    catch (...)
    {
        m_imp_ptr.reset();
    }
}

BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(const char* what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec) :
    system::system_error(ec, what_arg)
{
    try
    {
        m_imp_ptr.reset(new impl(path1_arg, path2_arg));
    }
    catch (...)
    {
        m_imp_ptr.reset();
    }
}

BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(std::string const& what_arg, path const& path1_arg, path const& path2_arg, system::error_code ec) :
    system::system_error(ec, what_arg)
{
    try
    {
        m_imp_ptr.reset(new impl(path1_arg, path2_arg));
    }
    catch (...)
    {
        m_imp_ptr.reset();
    }
}

BOOST_FILESYSTEM_DECL filesystem_error::filesystem_error(filesystem_error const& that) :
    system::system_error(static_cast< system::system_error const& >(that)),
    m_imp_ptr(that.m_imp_ptr)
{
}

BOOST_FILESYSTEM_DECL filesystem_error& filesystem_error::operator=(filesystem_error const& that)
{
    static_cast< system::system_error& >(*this) = static_cast< system::system_error const& >(that);
    m_imp_ptr = that.m_imp_ptr;
    return *this;
}

BOOST_FILESYSTEM_DECL filesystem_error::~filesystem_error() noexcept
{
}

BOOST_FILESYSTEM_DECL const char* filesystem_error::what() const noexcept
{
    if (m_imp_ptr.get()) try
    {
        if (m_imp_ptr->m_what.empty())
        {
            m_imp_ptr->m_what = system::system_error::what();
            if (!m_imp_ptr->m_path1.empty())
            {
                m_imp_ptr->m_what += ": \"";
                m_imp_ptr->m_what += m_imp_ptr->m_path1.string();
                m_imp_ptr->m_what += "\"";
            }
            if (!m_imp_ptr->m_path2.empty())
            {
                m_imp_ptr->m_what += ", \"";
                m_imp_ptr->m_what += m_imp_ptr->m_path2.string();
                m_imp_ptr->m_what += "\"";
            }
        }

        return m_imp_ptr->m_what.c_str();
    }
    catch (...)
    {
        m_imp_ptr->m_what.clear();
    }

    return system::system_error::what();
}

BOOST_FILESYSTEM_DECL path const& filesystem_error::get_empty_path() noexcept
{
    static const path empty_path;
    return empty_path;
}

//  error handling helpers declared in error_handling.hpp  -----------------------------------------------------//

void emit_error(err_t error_num, system::error_code* ec, const char* message)
{
    if (!ec)
        BOOST_FILESYSTEM_THROW(filesystem_error(message, system::error_code(error_num, system::system_category())));
    else
        ec->assign(error_num, system::system_category());
}

void emit_error(err_t error_num, path const& p, system::error_code* ec, const char* message)
{
    if (!ec)
        BOOST_FILESYSTEM_THROW(filesystem_error(message, p, system::error_code(error_num, system::system_category())));
    else
        ec->assign(error_num, system::system_category());
}

void emit_error(err_t error_num, path const& p1, path const& p2, system::error_code* ec, const char* message)
{
    if (!ec)
        BOOST_FILESYSTEM_THROW(filesystem_error(message, p1, p2, system::error_code(error_num, system::system_category())));
    else
        ec->assign(error_num, system::system_category());
}

} // namespace filesystem
} // namespace boost

#include <boost/filesystem/detail/footer.hpp>