• 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

4.76
/libs/core/errors/src/exception_list.cpp
1
//  Copyright (c) 2007-2025 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/config.hpp>
8
#include <hpx/errors/exception.hpp>
9
#include <hpx/errors/exception_list.hpp>
10
#include <hpx/modules/thread_support.hpp>
11

12
#include <exception>
13
#include <mutex>
14
#include <set>
15
#include <string>
16
#include <system_error>
17
#include <utility>
18

19
namespace hpx {
20
    namespace detail {
21
        std::string indent_message(std::string const& msg_)
×
22
        {
23
            std::string result;
24
            std::string const& msg(msg_);
25
            std::string::size_type pos = msg.find_first_of('\n');
26
            std::string::size_type first_non_ws = msg.find_first_not_of(" \n");
27
            std::string::size_type pos1 = 0;
28

29
            while (std::string::npos != pos)
×
30
            {
31
                if (pos > first_non_ws)
×
32
                {    // skip leading newline
33
                    result += msg.substr(pos1, pos - pos1 + 1);
×
34
                    pos = msg.find_first_of('\n', pos1 = pos + 1);
×
35
                    if (std::string::npos != pos)
×
36
                    {
37
                        result += "  ";
38
                    }
39
                }
40
                else
41
                {
42
                    pos = msg.find_first_of('\n', pos1 = pos + 1);
×
43
                }
44
            }
45

46
            result += msg.substr(pos1);
×
47
            return result;
×
48
        }
49
    }    // namespace detail
50

51
    error_code throws;    // "throw on error" special error_code;
52
                          //
53
                          // Note that it doesn't matter if this isn't
54
                          // initialized before use since the only use is
55
                          // to take its address for comparison purposes.
56

57
    exception_list::exception_list()
236✔
58
      : hpx::exception(hpx::error::success)
59
      , mtx_()
236✔
60
    {
61
    }
236✔
62

63
    exception_list::exception_list(std::exception_ptr const& e)
×
64
      : hpx::exception(hpx::get_error(e), hpx::get_error_what(e))
×
65
      , mtx_()
×
66
    {
67
        add_no_lock(e);
×
68
    }
×
69

70
    exception_list::exception_list(exception_list_type&& l)
×
71
      : hpx::exception(
72
            !l.empty() ? hpx::get_error(l.front()) : hpx::error::success)
×
73
      , exceptions_(HPX_MOVE(l))
74
      , mtx_()
×
75
    {
76
    }
×
77

78
    exception_list::exception_list(exception_list const& l)
×
79
      : hpx::exception(static_cast<hpx::exception const&>(l))
80
      , exceptions_(l.exceptions_)
×
81
      , mtx_()
×
82
    {
83
    }
×
84

85
    exception_list::exception_list(exception_list&& l) noexcept
×
86
      : hpx::exception(HPX_MOVE(static_cast<hpx::exception&>(l)))
87
      , exceptions_(HPX_MOVE(l.exceptions_))
88
      , mtx_()
×
89
    {
90
    }
×
91

92
    exception_list& exception_list::operator=(exception_list const& l)
×
93
    {
94
        if (this != &l)
×
95
        {
96
            *static_cast<hpx::exception*>(this) =
97
                static_cast<hpx::exception const&>(l);
98
            exceptions_ = l.exceptions_;
×
99
        }
100
        return *this;
×
101
    }
102

103
    exception_list& exception_list::operator=(exception_list&& l) noexcept
×
104
    {
105
        if (this != &l)
×
106
        {
107
            static_cast<hpx::exception&>(*this) =
108
                HPX_MOVE(static_cast<hpx::exception&>(l));
109
            exceptions_ = HPX_MOVE(l.exceptions_);
×
110
        }
111
        return *this;
×
112
    }
113

114
    ///////////////////////////////////////////////////////////////////////////
115
    std::error_code exception_list::get_error_code() const
×
116
    {
117
        std::lock_guard<mutex_type> l(mtx_);
×
118
        if (exceptions_.empty())
×
119
            return hpx::error::no_success;
×
120
        return hpx::get_error(exceptions_.front());
×
121
    }
122

123
    std::string exception_list::get_message() const
×
124
    {
125
        std::lock_guard<mutex_type> l(mtx_);
×
126
        if (exceptions_.empty())
×
127
            return "";
×
128

129
        if (1 == exceptions_.size())
×
130
            return hpx::get_error_what(exceptions_.front());
×
131

132
        std::string result("\n");
×
133

134
        exception_list_type::const_iterator end = exceptions_.end();
135
        exception_list_type::const_iterator it = exceptions_.begin();
136
        for (/**/; it != end; ++it)
×
137
        {
138
            result += "  ";
139
            result += detail::indent_message(hpx::get_error_what(*it));
×
140
            if (result.find_last_of('\n') < result.size() - 1)
×
141
                result += "\n";
142
        }
143
        return result;
×
144
    }
145

146
    void exception_list::add(std::exception_ptr const& e)
×
147
    {
148
        std::unique_lock<mutex_type> l(mtx_);
×
149
        if (exceptions_.empty())
×
150
        {
151
            hpx::exception ex;
×
152
            {
153
                unlock_guard<std::unique_lock<mutex_type>> ul(l);
154
                ex = hpx::exception(hpx::get_error(e), hpx::get_error_what(e));
×
155
            }
156

157
            // set the error code for our base class
158
            static_cast<hpx::exception&>(*this) = ex;
159
        }
×
160
        exceptions_.push_back(e);
×
161
    }
×
162

163
    void exception_list::add_no_lock(std::exception_ptr const& e)
×
164
    {
165
        exceptions_.push_back(e);
×
166
    }
×
167
}    // namespace hpx
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

© 2025 Coveralls, Inc