errors 0.6.3
Loading...
Searching...
No Matches
wrap_error.hpp
1#pragma once
2
3#include <string>
4
5#include "errors/impl/error_with_cause.hpp"
6
7namespace errors
8{
9namespace impl
10{
11
24 public:
34 : error_with_cause(std::move(cause), std::move(loc))
35 {
36 }
37
49 wrap_error(std::string msg, error_ptr &&cause, source_location loc)
50 : error_with_cause(std::move(cause), std::move(loc))
51 , message(std::move(msg))
52 {
53 }
54
55 const char *what() const noexcept override
56 {
57 return this->message.has_value() ? this->message->c_str() : "";
58 }
59
60 private:
61 std::optional<std::string> message;
62};
63static_assert(!std::is_abstract<wrap_error>());
64
65}
66}
Smart pointer to errors::error with some utility member functions.
Definition error_ptr.hpp:13
A base error class.
Definition error_with_cause.hpp:19
const error_ptr & cause() const &noexcept override
Get cause of this error, if any.
Definition error_with_cause.hpp:35
An error which wraps another error.
Definition wrap_error.hpp:23
const char * what() const noexcept override
Get error message.
Definition wrap_error.hpp:55
wrap_error(error_ptr &&cause, source_location loc)
Constructor with cause and source_location.
Definition wrap_error.hpp:33
wrap_error(std::string msg, error_ptr &&cause, source_location loc)
Constructor with message, cause and source_location.
Definition wrap_error.hpp:49
The source location.
Definition source_location.hpp:46