GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::exception_ptr(3) C++ Standard Libary std::exception_ptr(3)

std::exception_ptr - std::exception_ptr


Defined in header <exception>
typedef /*unspecified*/ exception_ptr; (since C++11)


std::exception_ptr is a nullable pointer-like type that manages an exception object
which has been thrown and captured with std::current_exception. An instance of
std::exception_ptr may be passed to another function, possibly on another thread,
where the exception may be rethrown and handled with a catch clause.


A default-constructed std::exception_ptr is a null pointer; it does not point to an
exception object.


Two instances of std::exception_ptr compare equal only if they are both null or both
point at the same exception object.


std::exception_ptr is not implicitly convertible to any arithmetic, enumeration, or
pointer type. It is contextually convertible to bool, and will evaluate to false if
it is null, true otherwise.


The exception object referenced by an std::exception_ptr remains valid as long as
there remains at least one std::exception_ptr that is referencing it:
std::exception_ptr is a shared-ownership smart pointer (note; this is in addition to
the usual exception object lifetime rules)


std::exception_ptr meets the requirements of NullablePointer.

// Run this code


#include <iostream>
#include <string>
#include <exception>
#include <stdexcept>


void handle_eptr(std::exception_ptr eptr) // passing by value is ok
{
try {
if (eptr) {
std::rethrow_exception(eptr);
}
} catch(const std::exception& e) {
std::cout << "Caught exception \"" << e.what() << "\"\n";
}
}


int main()
{
std::exception_ptr eptr;
try {
std::string().at(1); // this generates an std::out_of_range
} catch(...) {
eptr = std::current_exception(); // capture
}
handle_eptr(eptr);
} // destructor for std::out_of_range called here, when the eptr is destructed


Caught exception "basic_string::at"


make_exception_ptr creates an std::exception_ptr from an exception object
(C++11) (function template)
current_exception captures the current exception in a std::exception_ptr
(C++11) (function)
rethrow_exception throws the exception from an std::exception_ptr
(C++11) (function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.