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 {
30 class exception_dispatch_info final : public xtd::object {
31 public:
33 exception_dispatch_info() = default;
34 exception_dispatch_info(exception_dispatch_info&&) = default;
35 exception_dispatch_info(const exception_dispatch_info&) = default;
36 auto operator =(exception_dispatch_info&&) -> exception_dispatch_info& = default;
37 auto operator =(const exception_dispatch_info&) -> exception_dispatch_info& = default;
39
41
45 [[nodiscard]] auto exception_captured() const noexcept -> bool {return exception_ptr_ ? true : false;}
46
50 [[nodiscard]] auto source_exception() const noexcept -> xtd::ptr<xtd::exception> {return source_;}
52
54
61 template<class exception_t>
62 requires std::derived_from<exception_t, xtd::exception>
63 [[nodiscard]] static auto capture(const exception_t& source) -> exception_dispatch_info {
64 return exception_dispatch_info {source};
65 }
66
70 [[nodiscard]] static auto capture() -> exception_dispatch_info {
71 return exception_dispatch_info {std::current_exception()};
72 }
73
75 auto rethrow() -> void {if (exception_captured()) std::rethrow_exception(exception_ptr_);}
77 template<class exception_t>
78 static auto rethrow(const exception_t& source) -> void {exception_dispatch_info {source}.rethrow();}
80
82
86 explicit operator bool () const noexcept {return exception_captured();}
87 operator const std::exception_ptr& () const noexcept {return exception_ptr_;}
88 operator std::exception_ptr () noexcept {return exception_ptr_;}
90
91 private:
92 template<class exception_t>
93 exception_dispatch_info(const exception_t& source) : source_ {source.template memberwise_clone<exception_t>().release()}, exception_ptr_ {std::make_exception_ptr(source)} {}
94 exception_dispatch_info(const std::exception_ptr& exception_ptr) : exception_ptr_ {exception_ptr} {}
95
97 std::exception_ptr exception_ptr_;
98 };
99 }
100}
static auto capture(const exception_t &source) -> exception_dispatch_info
Creates an xtd::exception_services::exception_dispatch_info object that represents the specified exce...
Definition exception_dispatch_info.hpp:63
static auto capture() -> exception_dispatch_info
Creates an xtd::exception_services::exception_dispatch_info object that represents the specified exce...
Definition exception_dispatch_info.hpp:70
auto rethrow() -> void
Rethrows the exception that's represented by the current xtd::exception_services::exception_dispatch_...
Definition exception_dispatch_info.hpp:75
static auto rethrow(const exception_t &source) -> void
Rehrows the source exception, maintaining the original stack trace information.
Definition exception_dispatch_info.hpp:78
auto exception_captured() const noexcept -> bool
Gets a value indicating whether the exception is caught or not.
Definition exception_dispatch_info.hpp:45
auto source_exception() const noexcept -> xtd::ptr< xtd::exception >
Gets the exception that's represented by the current instance.
Definition exception_dispatch_info.hpp:50
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.
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:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::ptr type.