-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultipleException.hpp
43 lines (33 loc) · 1.11 KB
/
MultipleException.hpp
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
#ifndef MULTIPLE_EXCEPTION
#define MULTIPLE_EXCEPTION
#include <memory>
namespace safini
{
class MultipleException : public std::exception
{
public:
MultipleException(const MultipleException&) noexcept = default;
MultipleException(const std::string_view whatString)
{
m_ExceptionStringPtr->append("\n\t")
.append(whatString);
}
void addException(const std::string_view whatString)
{
SharedStorage newExceptionStringStorage{std::make_shared<std::string>(*m_ExceptionStringPtr)};
newExceptionStringStorage->append("\n\t")
.append(whatString);
m_ExceptionStringPtr = newExceptionStringStorage;
}
virtual const char* what() const noexcept override
{
return m_ExceptionStringPtr->c_str();
}
virtual ~MultipleException() = default;
private:
//we're doing COW because we need noexcept copy constructor
using SharedStorage = std::shared_ptr<std::string>;
SharedStorage m_ExceptionStringPtr{std::make_shared<std::string>("MultipleException:")};
};
}
#endif // MULTIPLE_EXCEPTION