A RetroSearch Logo

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

Search Query:

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

public member function

<exception>

std::exception::what
virtual const char* what() const throw();
virtual const char* what() const noexcept;

Get string identifying exception

Returns a null terminated character sequence that may be used to identify the exception.

The particular representation pointed by the returned value is implementation-defined.

As a virtual function, derived classes may redefine this function so that specific values are returned.



Parameters none

Return Value A pointer to a c-string with content related to the exception.
This is guaranteed to be valid at least until the exception object from which it is obtained is destroyed or until a non-const member function of the exception object is called.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// exception::what
#include <iostream>       // std::cout
#include <exception>      // std::exception

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

int main () {
  try {
      throw ooops();
  } catch (std::exception& ex) {
      std::cout << ex.what();
  }
  return 0;
}

Possible output:


Exception safetyNo-throw guarantee: this member function never throws exceptions.
This also applies to all derived classes within the C++ standard library.

See also
exception::exception
Construct 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