xtd 0.2.0
Loading...
Searching...
No Matches
exception_dispatch_info.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../../exception.hpp"
6#include "../../ptr.hpp"
7#include <exception>
8#include <type_traits>
9
11namespace xtd {
13 namespace runtime {
15 namespace exception_services {
32 class exception_dispatch_info final : public xtd::object {
33 public:
35 exception_dispatch_info() = default;
38 exception_dispatch_info& operator =(exception_dispatch_info&&) = default;
39 exception_dispatch_info& operator =(const exception_dispatch_info&) = default;
41
43
47 bool exception_captured() const noexcept {return exception_ptr_ ? true : false;}
48
52 xtd::ptr<xtd::exception> source_exception() const noexcept {return source_;}
54
56
63 template <typename exception_t>
64 static exception_dispatch_info capture(const exception_t& source) {
65 static_assert(std::is_base_of<xtd::exception, exception_t>::value);
66 return exception_dispatch_info {source};
67 }
68
70 void rethrow() {if (exception_captured()) std::rethrow_exception(exception_ptr_);}
72 template <typename exception_t>
73 static void rethrow(const exception_t& source) {exception_dispatch_info {source}.rethrow();}
75
77
81 explicit operator bool() const noexcept {return exception_captured();}
83
84 private:
85 template <typename exception_t>
86 exception_dispatch_info(const exception_t& source) : source_ {source.template memberwise_clone<exception_t>().release()}, exception_ptr_ {std::make_exception_ptr(source)} {}
87
89 std::exception_ptr exception_ptr_;
90 };
91 }
92 }
93}
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
xtd::uptr< object_t > memberwise_clone() const
Creates a shallow copy of the current object.
Definition object.hpp:99
Represents an exception whose state is captured at a certain point in code.
Definition exception_dispatch_info.hpp:32
static exception_dispatch_info capture(const exception_t &source)
Creates an xtd::runtime::exception_services::exception_dispatch_info object that represents the speci...
Definition exception_dispatch_info.hpp:64
static void rethrow(const exception_t &source)
Rehrows the source exception, maintaining the original stack trace information.
Definition exception_dispatch_info.hpp:73
bool exception_captured() const noexcept
Gets a value indicating whether the exception is caught or not.
Definition exception_dispatch_info.hpp:47
xtd::ptr< xtd::exception > source_exception() const noexcept
Gets the exception that's represented by the current instance.
Definition exception_dispatch_info.hpp:52
void rethrow()
Rethrows the exception that's represented by the current xtd::runtime::exception_services::exception_...
Definition exception_dispatch_info.hpp:70
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
@ release
Build type release.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10