A RetroSearch Logo

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

Search Query:

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

public member function

<exception>

std::exception::exception default (1)
exception() throw();
copy (2)
exception (const exception& e) throw();
default (1)
exception() noexcept;
copy (2)
exception (const exception& e) noexcept;

Construct exception

Constructs an exception object.

The effects of calling member

what

after a copy construction depend on the particular library implementation.


Every exception within the C++ standard library (including this) has, at least, a copy constructor that preserves the string representation returned by member

what

when the dynamic types match.



Parameters
e
Another exception object.

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 constructor
#include <iostream>       // std::cout
#include <exception>      // std::exception

struct ooops : std::exception {
  const char* what() const noexcept {return "Ooops!\n";}
};

int main () {
  ooops e;
  std::exception* p = &e;
  try {
      throw e;       // throwing copy-constructs: ooops(e)
  } catch (std::exception& ex) {
      std::cout << ex.what();
  }
  try {
      throw *p;      // throwing copy-constructs: std::exception(*p)
  } catch (std::exception& ex) {
      std::cout << ex.what();
  }
  return 0;
}

Possible output:


Exception safetyNo-throw guarantee: this member function never throws exceptions.

See also
exception::operator=
Copy exception (public member function)
exception::what
Get string identifying exception (public member function)

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