• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #853

19 Dec 2022 01:01AM UTC coverage: 86.287% (+0.4%) from 85.912%
#853

push

StellarBot
Merge #6109

6109: Modernize serialization module r=hkaiser a=hkaiser

- flyby separate serialization of Boost types

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497

Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

53 of 53 new or added lines in 6 files covered. (100.0%)

173939 of 201582 relevant lines covered (86.29%)

1931657.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.57
/libs/core/errors/include/hpx/errors/error_code.hpp
1
//  Copyright (c) 2007-2022 Hartmut Kaiser
2
//  Copyright (c) 2011      Bryce Lelbach
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
/// \file error_code.hpp
9

10
#pragma once
11

12
#include <hpx/config.hpp>
13
#include <hpx/errors/error.hpp>
14
#include <hpx/errors/exception_fwd.hpp>
15

16
#include <exception>
17
#include <stdexcept>
18
#include <string>
19
#include <system_error>
20

21
///////////////////////////////////////////////////////////////////////////////
22
namespace hpx {
23

24
    /// \cond NODETAIL
25
    namespace detail {
26
        HPX_CORE_EXPORT std::exception_ptr access_exception(error_code const&);
27

28
        ///////////////////////////////////////////////////////////////////////
29
        struct command_line_error : std::logic_error
×
30
        {
31
            explicit command_line_error(char const* msg)
×
32
              : std::logic_error(msg)
×
33
            {
×
34
            }
×
35

36
            explicit command_line_error(std::string const& msg)
×
37
              : std::logic_error(msg)
×
38
            {
×
39
            }
×
40
        };
41
    }    // namespace detail
42
    /// \endcond
43

44
    ///////////////////////////////////////////////////////////////////////////
45
    /// \brief Returns generic HPX error category used for new errors.
46
    HPX_CORE_EXPORT std::error_category const& get_hpx_category() noexcept;
47

48
    /// \brief Returns generic HPX error category used for errors re-thrown
49
    ///        after the exception has been de-serialized.
50
    HPX_CORE_EXPORT std::error_category const&
51
    get_hpx_rethrow_category() noexcept;
52

53
    /// \cond NOINTERNAL
54
    HPX_CORE_EXPORT std::error_category const&
55
    get_lightweight_hpx_category() noexcept;
56

57
    HPX_CORE_EXPORT std::error_category const& get_hpx_category(
58
        throwmode mode) noexcept;
59

60
    inline std::error_code make_system_error_code(
5,954,143✔
61
        error e, throwmode mode = throwmode::plain)
62
    {
63
        return std::error_code(static_cast<int>(e), get_hpx_category(mode));
5,953,706✔
64
    }
65

66
    ///////////////////////////////////////////////////////////////////////////
67
    inline std::error_condition make_error_condition(error e, throwmode mode)
68
    {
69
        return std::error_condition(
70
            static_cast<int>(e), get_hpx_category(mode));
71
    }
72
    /// \endcond
73

74
    ///////////////////////////////////////////////////////////////////////////
75
    /// \brief A hpx::error_code represents an arbitrary error condition.
76
    ///
77
    /// The class hpx::error_code describes an object used to hold error code
78
    /// values, such as those originating from the operating system or other
79
    /// low-level application program interfaces.
80
    ///
81
    /// \note Class hpx::error_code is an adjunct to error reporting by
82
    /// exception
83
    ///
84
    class error_code : public std::error_code    //-V690
5,962,007✔
85
    {
86
    public:
87
        /// Construct an object of type error_code.
88
        ///
89
        /// \param mode   The parameter \p mode specifies whether the constructed
90
        ///               hpx::error_code belongs to the error category
91
        ///               \a hpx_category (if mode is \a plain, this is the
92
        ///               default) or to the category \a hpx_category_rethrow
93
        ///               (if mode is \a rethrow).
94
        ///
95
        /// \throws nothing
96
        explicit error_code(throwmode mode = throwmode::plain)
5,845,480✔
97
          : std::error_code(make_system_error_code(hpx::error::success, mode))
5,845,577✔
98
        {
5,845,577✔
99
        }
5,845,577✔
100

101
        /// Construct an object of type error_code.
102
        ///
103
        /// \param e      The parameter \p e holds the hpx::error code the new
104
        ///               exception should encapsulate.
105
        /// \param mode   The parameter \p mode specifies whether the constructed
106
        ///               hpx::error_code belongs to the error category
107
        ///               \a hpx_category (if mode is \a plain, this is the
108
        ///               default) or to the category \a hpx_category_rethrow
109
        ///               (if mode is \a rethrow).
110
        ///
111
        /// \throws nothing
112
        HPX_CORE_EXPORT explicit error_code(
113
            error e, throwmode mode = throwmode::plain);
114

115
        /// Construct an object of type error_code.
116
        ///
117
        /// \param e      The parameter \p e holds the hpx::error code the new
118
        ///               exception should encapsulate.
119
        /// \param func   The name of the function where the error was raised.
120
        /// \param file   The file name of the code where the error was raised.
121
        /// \param line   The line number of the code line where the error was
122
        ///               raised.
123
        /// \param mode   The parameter \p mode specifies whether the constructed
124
        ///               hpx::error_code belongs to the error category
125
        ///               \a hpx_category (if mode is \a plain, this is the
126
        ///               default) or to the category \a hpx_category_rethrow
127
        ///               (if mode is \a rethrow).
128
        ///
129
        /// \throws nothing
130
        HPX_CORE_EXPORT error_code(error e, char const* func, char const* file,
131
            long line, throwmode mode = throwmode::plain);
132

133
        /// Construct an object of type error_code.
134
        ///
135
        /// \param e      The parameter \p e holds the hpx::error code the new
136
        ///               exception should encapsulate.
137
        /// \param msg    The parameter \p msg holds the error message the new
138
        ///               exception should encapsulate.
139
        /// \param mode   The parameter \p mode specifies whether the constructed
140
        ///               hpx::error_code belongs to the error category
141
        ///               \a hpx_category (if mode is \a plain, this is the
142
        ///               default) or to the category \a hpx_category_rethrow
143
        ///               (if mode is \a rethrow).
144
        ///
145
        /// \throws std#bad_alloc (if allocation of a copy of
146
        ///         the passed string fails).
147
        HPX_CORE_EXPORT error_code(
148
            error e, char const* msg, throwmode mode = throwmode::plain);
149

150
        /// Construct an object of type error_code.
151
        ///
152
        /// \param e      The parameter \p e holds the hpx::error code the new
153
        ///               exception should encapsulate.
154
        /// \param msg    The parameter \p msg holds the error message the new
155
        ///               exception should encapsulate.
156
        /// \param func   The name of the function where the error was raised.
157
        /// \param file   The file name of the code where the error was raised.
158
        /// \param line   The line number of the code line where the error was
159
        ///               raised.
160
        /// \param mode   The parameter \p mode specifies whether the constructed
161
        ///               hpx::error_code belongs to the error category
162
        ///               \a hpx_category (if mode is \a plain, this is the
163
        ///               default) or to the category \a hpx_category_rethrow
164
        ///               (if mode is \a rethrow).
165
        ///
166
        /// \throws std#bad_alloc (if allocation of a copy of
167
        ///         the passed string fails).
168
        HPX_CORE_EXPORT error_code(error e, char const* msg, char const* func,
169
            char const* file, long line, throwmode mode = throwmode::plain);
170

171
        /// Construct an object of type error_code.
172
        ///
173
        /// \param e      The parameter \p e holds the hpx::error code the new
174
        ///               exception should encapsulate.
175
        /// \param msg    The parameter \p msg holds the error message the new
176
        ///               exception should encapsulate.
177
        /// \param mode   The parameter \p mode specifies whether the constructed
178
        ///               hpx::error_code belongs to the error category
179
        ///               \a hpx_category (if mode is \a plain, this is the
180
        ///               default) or to the category \a hpx_category_rethrow
181
        ///               (if mode is \a rethrow).
182
        ///
183
        /// \throws std#bad_alloc (if allocation of a copy of
184
        ///         the passed string fails).
185
        HPX_CORE_EXPORT error_code(
186
            error e, std::string const& msg, throwmode mode = throwmode::plain);
187

188
        /// Construct an object of type error_code.
189
        ///
190
        /// \param e      The parameter \p e holds the hpx::error code the new
191
        ///               exception should encapsulate.
192
        /// \param msg    The parameter \p msg holds the error message the new
193
        ///               exception should encapsulate.
194
        /// \param func   The name of the function where the error was raised.
195
        /// \param file   The file name of the code where the error was raised.
196
        /// \param line   The line number of the code line where the error was
197
        ///               raised.
198
        /// \param mode   The parameter \p mode specifies whether the constructed
199
        ///               hpx::error_code belongs to the error category
200
        ///               \a hpx_category (if mode is \a plain, this is the
201
        ///               default) or to the category \a hpx_category_rethrow
202
        ///               (if mode is \a rethrow).
203
        ///
204
        /// \throws std#bad_alloc (if allocation of a copy of
205
        ///         the passed string fails).
206
        HPX_CORE_EXPORT error_code(error e, std::string const& msg,
207
            char const* func, char const* file, long line,
208
            throwmode mode = throwmode::plain);
209

210
        /// Return a reference to the error message stored in the hpx::error_code.
211
        ///
212
        /// \throws nothing
213
        HPX_CORE_EXPORT std::string get_message() const;
214

215
        /// \brief Clear this error_code object.
216
        /// The postconditions of invoking this method are
217
        /// * value() == hpx::error::success and
218
        ///   category() == hpx::get_hpx_category()
219
        void clear()
220
        {
221
            this->std::error_code::assign(
222
                static_cast<int>(hpx::error::success), get_hpx_category());
223
            exception_ = std::exception_ptr();
224
        }
225

226
        /// Copy constructor for error_code
227
        ///
228
        /// \note This function maintains the error category of the left hand
229
        ///       side if the right hand side is a success code.
230
        HPX_CORE_EXPORT error_code(error_code const& rhs);
231

232
        /// Assignment operator for error_code
233
        ///
234
        /// \note This function maintains the error category of the left hand
235
        ///       side if the right hand side is a success code.
236
        HPX_CORE_EXPORT error_code& operator=(error_code const& rhs);
237

238
    private:
239
        friend std::exception_ptr detail::access_exception(error_code const&);
240
        friend class exception;
241
        friend error_code make_error_code(std::exception_ptr const&);
242

243
        HPX_CORE_EXPORT error_code(int err, hpx::exception const& e);
244
        HPX_CORE_EXPORT explicit error_code(std::exception_ptr const& e);
245

246
        std::exception_ptr exception_;
247
    };
248

249
    /// @{
250
    /// \brief Returns a new error_code constructed from the given parameters.
251
    inline error_code make_error_code(
91,573✔
252
        error e, throwmode mode = throwmode::plain)
253
    {
254
        return error_code(e, mode);
91,573✔
255
    }
256

257
    inline error_code make_error_code(error e, char const* func,
258
        char const* file, long line, throwmode mode = throwmode::plain)
259
    {
260
        return error_code(e, func, file, line, mode);
261
    }
262

263
    /// \brief Returns error_code(e, msg, mode).
264
    inline error_code make_error_code(
×
265
        error e, char const* msg, throwmode mode = throwmode::plain)
266
    {
267
        return error_code(e, msg, mode);
×
268
    }
269

270
    inline error_code make_error_code(error e, char const* msg,
×
271
        char const* func, char const* file, long line,
272
        throwmode mode = throwmode::plain)
273
    {
274
        return error_code(e, msg, func, file, line, mode);
×
275
    }
276

277
    /// \brief Returns error_code(e, msg, mode).
278
    inline error_code make_error_code(
279
        error e, std::string const& msg, throwmode mode = throwmode::plain)
280
    {
281
        return error_code(e, msg, mode);
282
    }
283

284
    inline error_code make_error_code(error e, std::string const& msg,
6,296✔
285
        char const* func, char const* file, long line,
286
        throwmode mode = throwmode::plain)
287
    {
288
        return error_code(e, msg, func, file, line, mode);
6,296✔
289
    }
290

291
    inline error_code make_error_code(std::exception_ptr const& e)
5,496✔
292
    {
293
        return error_code(e);
5,496✔
294
    }
295
    ///@}
296

297
    /// \brief Returns error_code(hpx::error::success, "success", mode).
298
    inline error_code make_success_code(throwmode mode = throwmode::plain)
4,329,958✔
299
    {
300
        return error_code(mode);
4,329,960✔
301
    }
302
}    // namespace hpx
303

304
#include <hpx/errors/throw_exception.hpp>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc