GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::abort(3) C++ Standard Libary std::abort(3)

std::abort - std::abort


Defined in header <cstdlib>
void abort(); (until C++11)
[[noreturn]] void abort() noexcept; (since C++11)


Causes abnormal program termination unless SIGABRT is being caught by a signal
handler passed to std::signal and the handler does not return.


Destructors of variables with automatic,
thread local
(since C++11) and static storage durations are not called. Functions registered with
std::atexit()
and std::at_quick_exit
(since C++11) are also not called. Whether open resources such as files are closed
is implementation defined. An implementation defined status is returned to the host
environment that indicates unsuccessful execution.


(none)


None because it does not return.


Throws nothing.


POSIX specifies that the abort() function overrides blocking or ignoring the SIGABRT
signal.


Some compiler intrinsics, e.g. __builtin_trap (gcc, clang, and icc) or __debugbreak
(msvc), can be used to terminate the program as fast as possible.

// Run this code


#include <csignal>
#include <iostream>
#include <cstdlib>


class Tester {
public:
Tester() { std::cout << "Tester ctor\n"; }
~Tester() { std::cout << "Tester dtor\n"; }
};


Tester static_tester; // Destructor not called


void signal_handler(int signal)
{
if (signal == SIGABRT) {
std::cerr << "SIGABRT received\n";
} else {
std::cerr << "Unexpected signal " << signal << " received\n";
}
std::_Exit(EXIT_FAILURE);
}


int main()
{
Tester automatic_tester; // Destructor not called


// Setup handler
auto previous_handler = std::signal(SIGABRT, signal_handler);
if (previous_handler == SIG_ERR) {
std::cerr << "Setup failed\n";
return EXIT_FAILURE;
}


std::abort(); // Raise SIGABRT
std::cout << "This code is unreachable\n";
}


Tester ctor
Tester ctor
SIGABRT received


exit causes normal program termination with cleaning up
(function)
atexit registers a function to be called on std::exit() invocation
(function)
quick_exit causes quick program termination without completely cleaning up
(C++11) (function)
at_quick_exit registers a function to be called on std::quick_exit invocation
(C++11) (function)
signal sets a signal handler for particular signal
(function)
terminate function called when exception handling fails
(function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.