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:
Ooops!
exception


Exception safety

No-throw guarantee: this member function never throws exceptions.

See also