A RetroSearch Logo

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

Search Query:

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

function

<exception>

std::terminate
[[noreturn]] void terminate() noexcept;

Function handling termination on exception

Calls the current terminate handler.

By default, the terminate handler calls abort. But this behavior can be redefined by calling set_terminate.

This function is automatically called when no catch handler can be found for a thrown exception, or for some other exceptional circumstance that makes impossible to continue the exception handling process.

This function is provided so that the terminate handler can be explicitly called by a program that needs to abnormally terminate, and works even if set_terminate has not been used to set a custom terminate handler (calling abort in this case).



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
// terminate example
#include <iostream>       // std::cout, std::cerr
#include <exception>      // std::exception, std::terminate

int main (void) {
  char* p;
  std::cout << "Attempting to allocate 1 GiB...";
  try {
    p = new char [1024*1024*1024];
  }
  catch (std::exception& e) {
    std::cerr << "ERROR: could not allocate storage\n";
    std::terminate();
  }
  std::cout << "Ok\n";
  delete[] p;
  return 0;
}

Possible output:
Attempting to allocate 1 GiB... Ok


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

See also
set_terminate
Set terminate handler function (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