xtd 1.0.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;
35
37
41 [[nodiscard]] auto captured() const noexcept -> bool {return exception_ptr_ ? true : false;}
42
46 [[nodiscard]] auto source_exception() const noexcept -> xtd::ptr<std::exception> {return source_;}
48
50
57 template<typename exception_t>
58 [[nodiscard]] static auto capture(const exception_t& source) -> exception_dispatch_info {
59 return exception_dispatch_info {source};
60 }
61
65 [[nodiscard]] static auto capture() -> exception_dispatch_info {
66 return exception_dispatch_info {std::current_exception()};
67 }
68
70 auto rethrow() -> void {if (captured()) std::rethrow_exception(exception_ptr_);}
72 template<typename exception_t>
73 static auto rethrow(const exception_t& source) -> void {exception_dispatch_info {source}.rethrow();}
75
77
81 explicit operator bool () const noexcept {return captured();}
82 operator const std::exception_ptr& () const noexcept {return exception_ptr_;}
83 operator std::exception_ptr () noexcept {return exception_ptr_;}
85
86 private:
87 template<typename exception_t>
88 explicit exception_dispatch_info(const exception_t& source) : source_ {xtd::new_ptr<exception_t>(source)}, exception_ptr_ {std::make_exception_ptr(source)} {}
89 explicit exception_dispatch_info(const std::exception_ptr& exception_ptr) : exception_ptr_ {exception_ptr} {}
90
92 std::exception_ptr exception_ptr_;
93 };
94 }
95}
auto captured() const noexcept -> bool
Gets a value indicating whether the exception is caught or not.
Definition exception_dispatch_info.hpp:41
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:58
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:65
auto rethrow() -> void
Rethrows the exception that's represented by the current xtd::exception_services::exception_dispatch_...
Definition exception_dispatch_info.hpp:70
static auto rethrow(const exception_t &source) -> void
Rehrows the source exception, maintaining the original stack trace information.
Definition exception_dispatch_info.hpp:73
auto source_exception() const noexcept -> xtd::ptr< std::exception >
Gets the exception that's represented by the current instance.
Definition exception_dispatch_info.hpp:46
Defines the base class for predefined exceptions in the xtd namespace.
Definition exception.hpp:34
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
Contains xtd::exception exception.
xtd::sptr< type_t > ptr
The xtd::ptr object is a shared pointer.
Definition ptr.hpp:27
auto new_ptr(args_t &&... args) -> xtd::ptr< type_t >
The xtd::new_ptr operator creates a xtd::ptr object.
Definition new_ptr.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.