errors 0.6.3
Loading...
Searching...
No Matches
exception_error.hpp
1
2#pragma once
3
4#include <cassert>
5
6#include "errors/impl/error_without_cause.hpp"
7
8namespace errors
9{
10namespace impl
11{
12
19 public:
31 exception_error(std::exception_ptr exception, source_location location)
32 : error_without_cause(std::move(location))
33 , exception_ptr(std::move(exception))
34 {
35 }
36
43 : error_without_cause(std::move(location))
44 , exception_ptr(std::current_exception())
45 {
46 }
47
54 const char *what() const noexcept override
55 {
56 try {
57 if (!this->exception_ptr) {
58 return "";
59 }
60 std::rethrow_exception(this->exception_ptr);
61 } catch (const std::exception &e) {
62 return e.what();
63 } catch (...) {
64 return "Unknown exception";
65 }
66 }
67
70 std::exception_ptr exception_ptr;
71};
72static_assert(!std::is_abstract<exception_error>());
73
74}
75}
std::optional< source_location > location() const noexcept override
Get the source location of this error, if any.
Definition base_error.hpp:28
A base error class.
Definition error_without_cause.hpp:18
An error that has an exception.
Definition exception_error.hpp:18
exception_error(source_location location)
Create an exception error from the current exception.
Definition exception_error.hpp:42
exception_error(std::exception_ptr exception, source_location location)
Create an exception error from an exception pointer.
Definition exception_error.hpp:31
std::exception_ptr exception_ptr
The exception pointer.
Definition exception_error.hpp:70
const char * what() const noexcept override
Get the exception message.
Definition exception_error.hpp:54
The source location.
Definition source_location.hpp:46