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

STEllAR-GROUP / hpx / #882

31 Aug 2023 07:44PM UTC coverage: 41.798% (-44.7%) from 86.546%
#882

push

19442 of 46514 relevant lines covered (41.8%)

126375.38 hits per line

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

58.33
/libs/core/errors/include/hpx/errors/error_code.hpp
1
//  Copyright (c) 2007-2025 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
/// \page hpx::error_code
10
/// \headerfile hpx/system_error.hpp
11

12
#pragma once
13

14
#include <hpx/config.hpp>
15
#include <hpx/errors/error.hpp>
16
#include <hpx/errors/exception_fwd.hpp>
17

18
#include <exception>
19
#include <stdexcept>
20
#include <string>
21
#include <system_error>
22

23
#include <hpx/config/warnings_prefix.hpp>
24

25
///////////////////////////////////////////////////////////////////////////////
26
namespace hpx {
27

28
    /// \cond NODETAIL
29
    namespace detail {
30

31
        HPX_CXX_EXPORT [[nodiscard]] HPX_CORE_EXPORT std::exception_ptr
32
        access_exception(error_code const&);
33

34
        ///////////////////////////////////////////////////////////////////////
35
        HPX_CXX_EXPORT struct HPX_ALWAYS_EXPORT command_line_error final
36
          : std::logic_error
×
37
        {
38
            explicit command_line_error(char const* msg)
39
              : std::logic_error(msg)
40
            {
41
            }
×
42

43
            explicit command_line_error(std::string const& msg)
44
              : std::logic_error(msg)
45
            {
46
            }
47
        };
48
    }    // namespace detail
49
    /// \endcond
50

51
    ///////////////////////////////////////////////////////////////////////////
52
    /// \brief Returns generic HPX error category used for new errors.
53
    HPX_CXX_EXPORT [[nodiscard]] HPX_CORE_EXPORT std::error_category const&
54
    get_hpx_category() noexcept;
55

56
    /// \brief Returns generic HPX error category used for errors re-thrown
57
    ///        after the exception has been de-serialized.
58
    HPX_CXX_EXPORT [[nodiscard]] HPX_CORE_EXPORT std::error_category const&
59
    get_hpx_rethrow_category() noexcept;
60

61
    /// \cond NOINTERNAL
62
    HPX_CXX_EXPORT [[nodiscard]] HPX_CORE_EXPORT std::error_category const&
63
    get_lightweight_hpx_category() noexcept;
64

65
    HPX_CXX_EXPORT [[nodiscard]] HPX_CORE_EXPORT std::error_category const&
66
    get_hpx_category(throwmode mode) noexcept;
67

68
    HPX_CXX_EXPORT [[nodiscard]] inline std::error_code make_system_error_code(
56,215✔
69
        error e, throwmode mode = throwmode::plain)
70
    {
71
        return {static_cast<int>(e), get_hpx_category(mode)};
72
    }
73

74
    ///////////////////////////////////////////////////////////////////////////
75
    HPX_CXX_EXPORT [[nodiscard]] inline std::error_condition
76
    make_error_condition(error e, throwmode mode)
77
    {
78
        return {static_cast<int>(e), get_hpx_category(mode)};
79
    }
80
    /// \endcond
81

82
    HPX_CXX_EXPORT [[nodiscard]] inline error_code make_error_code(
83
        std::exception_ptr const& e);
84

85
    ///////////////////////////////////////////////////////////////////////////
86
    /// \brief A hpx::error_code represents an arbitrary error condition.
87
    ///
88
    /// The class hpx::error_code describes an object used to hold error code
89
    /// values, such as those originating from the operating system or other
67,172✔
90
    /// low-level application program interfaces.
91
    ///
92
    /// \note Class hpx::error_code is an adjunct to error reporting by
93
    /// exception
94
    ///
95
    HPX_CXX_EXPORT class HPX_CORE_EXPORT error_code
96
      : public std::error_code    //-V690
97
    {
98
    public:
99
        /// Construct an object of type error_code.
100
        ///
101
        /// \param mode   The parameter \p mode specifies whether the constructed
102
        ///               hpx::error_code belongs to the error category
61,401✔
103
        ///               \a hpx_category (if mode is \a plain, this is the
104
        ///               default) or to the category \a hpx_category_rethrow
130✔
105
        ///               (if mode is \a rethrow).
106
        ///
107
        /// \throws nothing
108
        explicit error_code(throwmode mode = throwmode::plain)
109
          : std::error_code(make_system_error_code(hpx::error::success, mode))
110
        {
111
        }
112

113
        /// Construct an object of type error_code.
114
        ///
115
        /// \param e      The parameter \p e holds the hpx::error code the new
116
        ///               exception should encapsulate.
117
        /// \param mode   The parameter \p mode specifies whether the constructed
118
        ///               hpx::error_code belongs to the error category
119
        ///               \a hpx_category (if mode is \a plain, this is the
120
        ///               default) or to the category \a hpx_category_rethrow
121
        ///               (if mode is \a rethrow).
122
        ///
123
        /// \throws nothing
124
        explicit error_code(error e, throwmode mode = throwmode::plain);
125

126
        /// Construct an object of type error_code.
127
        ///
128
        /// \param e      The parameter \p e holds the hpx::error code the new
129
        ///               exception should encapsulate.
130
        /// \param func   The name of the function where the error was raised.
131
        /// \param file   The file name of the code where the error was raised.
132
        /// \param line   The line number of the code line where the error was
133
        ///               raised.
134
        /// \param mode   The parameter \p mode specifies whether the constructed
135
        ///               hpx::error_code belongs to the error category
136
        ///               \a hpx_category (if mode is \a plain, this is the
137
        ///               default) or to the category \a hpx_category_rethrow
138
        ///               (if mode is \a rethrow).
139
        ///
140
        /// \throws nothing
141
        error_code(error e, char const* func, char const* file, long line,
142
            throwmode mode = throwmode::plain);
143

144
        /// Construct an object of type error_code.
145
        ///
146
        /// \param e      The parameter \p e holds the hpx::error code the new
147
        ///               exception should encapsulate.
148
        /// \param msg    The parameter \p msg holds the error message the new
149
        ///               exception should encapsulate.
150
        /// \param mode   The parameter \p mode specifies whether the constructed
151
        ///               hpx::error_code belongs to the error category
152
        ///               \a hpx_category (if mode is \a plain, this is the
153
        ///               default) or to the category \a hpx_category_rethrow
154
        ///               (if mode is \a rethrow).
155
        ///
156
        /// \throws std#bad_alloc (if allocation of a copy of
157
        ///         the passed string fails).
158
        error_code(error e, char const* msg, throwmode mode = throwmode::plain);
159

160
        /// Construct an object of type error_code.
161
        ///
162
        /// \param e      The parameter \p e holds the hpx::error code the new
163
        ///               exception should encapsulate.
164
        /// \param msg    The parameter \p msg holds the error message the new
165
        ///               exception should encapsulate.
166
        /// \param func   The name of the function where the error was raised.
167
        /// \param file   The file name of the code where the error was raised.
168
        /// \param line   The line number of the code line where the error was
169
        ///               raised.
170
        /// \param mode   The parameter \p mode specifies whether the constructed
171
        ///               hpx::error_code belongs to the error category
172
        ///               \a hpx_category (if mode is \a plain, this is the
173
        ///               default) or to the category \a hpx_category_rethrow
174
        ///               (if mode is \a rethrow).
175
        ///
176
        /// \throws std#bad_alloc (if allocation of a copy of
177
        ///         the passed string fails).
178
        error_code(error e, char const* msg, char const* func, char const* file,
179
            long line, throwmode mode = throwmode::plain);
180

181
        /// Construct an object of type error_code.
182
        ///
183
        /// \param e      The parameter \p e holds the hpx::error code the new
184
        ///               exception should encapsulate.
185
        /// \param msg    The parameter \p msg holds the error message the new
186
        ///               exception should encapsulate.
187
        /// \param mode   The parameter \p mode specifies whether the constructed
188
        ///               hpx::error_code belongs to the error category
189
        ///               \a hpx_category (if mode is \a plain, this is the
190
        ///               default) or to the category \a hpx_category_rethrow
191
        ///               (if mode is \a rethrow).
192
        ///
193
        /// \throws std#bad_alloc (if allocation of a copy of
194
        ///         the passed string fails).
195
        error_code(
196
            error e, std::string const& msg, throwmode mode = throwmode::plain);
197

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

219
        error_code(error_code&&) = default;
220
        error_code& operator=(error_code&&) = default;
221

222
        ~error_code() = default;
223

224
        /// Return a reference to the error message stored in the hpx::error_code.
225
        ///
226
        /// \throws nothing
227
        [[nodiscard]] std::string get_message() const;
228

229
        /// \brief Clear this error_code object.
230
        /// The postconditions of invoking this method are
231
        /// * value() == hpx::error::success and
232
        ///   category() == hpx::get_hpx_category()
233
        void clear()
234
        {
235
            this->std::error_code::assign(
236
                static_cast<int>(hpx::error::success), get_hpx_category());
237
            exception_ = std::exception_ptr();
238
        }
239

240
        /// Copy constructor for error_code
241
        ///
242
        /// \note This function maintains the error category of the left hand
243
        ///       side if the right hand side is a success code.
244
        error_code(error_code const& rhs);
245

246
        /// Assignment operator for error_code
247
        ///
248
        /// \note This function maintains the error category of the left hand
249
        ///       side if the right hand side is a success code.
250
        error_code& operator=(error_code const& rhs);
251

252
    private:
253
        friend std::exception_ptr detail::access_exception(error_code const&);
254
        friend class exception;
255
        friend error_code make_error_code(std::exception_ptr const&);
256

257
        error_code(int err, hpx::exception const& e);
258
        explicit error_code(std::exception_ptr const& e);
259

236✔
260
        std::exception_ptr exception_;
261
    };
262

263
    /// @{
264
    /// \brief Returns a new error_code constructed from the given parameters.
265
    HPX_CXX_EXPORT [[nodiscard]] inline error_code make_error_code(
266
        error e, throwmode mode = throwmode::plain)
267
    {
268
        return error_code(e, mode);
269
    }
270

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

278
    /// \brief Returns error_code(e, msg, mode).
279
    HPX_CXX_EXPORT [[nodiscard]] inline error_code make_error_code(
×
280
        error e, char const* msg, throwmode mode = throwmode::plain)
281
    {
282
        return {e, msg, mode};
283
    }
284

285
    HPX_CXX_EXPORT [[nodiscard]] inline error_code make_error_code(error e,
286
        char const* msg, char const* func, char const* file, long line,
287
        throwmode mode = throwmode::plain)
288
    {
289
        return {e, msg, func, file, line, mode};
290
    }
291

292
    /// \brief Returns error_code(e, msg, mode).
293
    HPX_CXX_EXPORT [[nodiscard]] inline error_code make_error_code(
1,504✔
294
        error e, std::string const& msg, throwmode mode = throwmode::plain)
295
    {
296
        return {e, msg, mode};
297
    }
298

1✔
299
    HPX_CXX_EXPORT [[nodiscard]] inline error_code make_error_code(error e,
300
        std::string const& msg, char const* func, char const* file, long line,
301
        throwmode mode = throwmode::plain)
302
    {
303
        return {e, msg, func, file, line, mode};
304
    }
305

306
    HPX_CXX_EXPORT [[nodiscard]] inline error_code make_error_code(
×
307
        std::exception_ptr const& e)
308
    {
309
        return error_code(e);
310
    }
311
    ///@}
312

313
    /// \brief Returns error_code(hpx::error::success, "success", mode).
314
    HPX_CXX_EXPORT [[nodiscard]] inline error_code make_success_code(
315
        throwmode mode = throwmode::plain)
316
    {
317
        return error_code(mode);
318
    }
319
}    // namespace hpx
320

321
#include <hpx/config/warnings_suffix.hpp>
322

323
#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