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 {
32 class exception_dispatch_info final : public xtd::object {
33 public:
35 exception_dispatch_info() = default;
36 exception_dispatch_info(exception_dispatch_info&&) = default;
37 exception_dispatch_info(const exception_dispatch_info&) = default;
38 auto operator =(exception_dispatch_info&&) -> exception_dispatch_info& = default;
39 auto operator =(const exception_dispatch_info&) -> exception_dispatch_info& = default;
41
43
47 [[nodiscard]] auto exception_captured() const noexcept -> bool {return exception_ptr_ ? true : false;}
48
52 [[nodiscard]] auto source_exception() const noexcept -> xtd::ptr<xtd::exception> {return source_;}
54
56
63 template<class exception_t>
64 requires std::derived_from<exception_t, xtd::exception>
65 [[nodiscard]] static auto capture(const exception_t& source) -> exception_dispatch_info {
66 return exception_dispatch_info {source};
67 }
68
72 [[nodiscard]] static auto capture() -> exception_dispatch_info {
73 return exception_dispatch_info {std::current_exception()};
74 }
75
77 auto rethrow() -> void {if (exception_captured()) std::rethrow_exception(exception_ptr_);}
79 template<class exception_t>
80 static auto rethrow(const exception_t& source) -> void {exception_dispatch_info {source}.rethrow();}
82
84
88 explicit operator bool () const noexcept {return exception_captured();}
89 operator const std::exception_ptr& () const noexcept {return exception_ptr_;}
90 operator std::exception_ptr () noexcept {return exception_ptr_;}
92
93 private:
94 template<class exception_t>
95 exception_dispatch_info(const exception_t& source) : source_ {source.template memberwise_clone<exception_t>().release()}, exception_ptr_ {std::make_exception_ptr(source)} {}
96 exception_dispatch_info(const std::exception_ptr& exception_ptr) : exception_ptr_ {exception_ptr} {}
97
99 std::exception_ptr exception_ptr_;
100 };
101 }
102 }
103}
Defines the base class for predefined exceptions in the xtd namespace.
Definition exception.hpp:29
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
xtd::unique_ptr_object< object_t > memberwise_clone() const
Creates a shallow copy of the current object.
static auto rethrow(const exception_t &source) -> void
Rehrows the source exception, maintaining the original stack trace information.
Definition exception_dispatch_info.hpp:80
auto rethrow() -> void
Rethrows the exception that's represented by the current xtd::runtime::exception_services::exception_...
Definition exception_dispatch_info.hpp:77
auto exception_captured() const noexcept -> bool
Gets a value indicating whether the exception is caught or not.
Definition exception_dispatch_info.hpp:47
static auto capture() -> exception_dispatch_info
Creates an xtd::runtime::exception_services::exception_dispatch_info object that represents the speci...
Definition exception_dispatch_info.hpp:72
static auto capture(const exception_t &source) -> exception_dispatch_info
Creates an xtd::runtime::exception_services::exception_dispatch_info object that represents the speci...
Definition exception_dispatch_info.hpp:65
auto source_exception() const noexcept -> xtd::ptr< xtd::exception >
Gets the exception that's represented by the current instance.
Definition exception_dispatch_info.hpp:52
Contains xtd::exception exception.
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
@ release
Build type release.
Definition build_type.hpp:24
Provides classes for advanced exception handling.
Definition exception_dispatch_info.hpp:15
Contains advanced types that support diverse namespaces such as the xtd, runtime, and the security na...
Definition exception_dispatch_info.hpp:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::ptr type.