A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/exception/rethrow_exception/ below:

function

<exception>

std::rethrow_exception
[[noreturn]] void rethrow_exception (exception_ptr p);

Rethrow exception

Throws the exception object pointed by p.

Parameters
p
An exception_ptr object pointing to an exception object.
This argument shall not be a null exception_ptr.
exception_ptr is a pointer-like type that points to exceptions.

Return value none (the function never returns).

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// exception_ptr example
#include <iostream>       // std::cout
#include <exception>      // std::exception_ptr, std::current_exception, std::rethrow_exception
#include <stdexcept>      // std::logic_error

int main () {
  std::exception_ptr p;
  try {
     throw std::logic_error("some logic_error exception");   // throws
  } catch(const std::exception& e) {
     p = std::current_exception();
     std::cout << "exception caught, but continuing...\n";
  }

  std::cout << "(after exception)\n";

  try {
     std::rethrow_exception (p);
  } catch (const std::exception& e) {
     std::cout << "exception caught: " << e.what() << '\n';
  }
  return 0;
}

Output:
exception caught, but continuing...
(after exception)
exception caught: some logic_error exception


Data races Concurrently calling rethrow_exception on exception_ptr objects that refer to the same exception is safe.

Note though that some implementations may not perform a copy of the pointed object on entering the catch exception handling block, and concurrently accessing the rethrown exception object in this case may introduce a data race.



Exception safety Throws an exception.

If p is a null exception_ptr, it causes undefined behavior.



See also
current_exception
Get smart pointer to current exception (function)
make_exception_ptr
Make exception_ptr (function template)
exception_ptr
Exception pointer (type)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4