< cpp‎ | utility‎ | program
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
Relational operators (deprecated in C++20)
Integer comparison functions
Swap and type operations
Common vocabulary types

Elementary string conversions
Program support utilities
Program termination
Communicating with the environment
Signal types
Non-local jumps
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.


[edit] Parameters


[edit] Return value


[edit] Exceptions

Throws nothing.

[edit] Notes

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

[edit] Example

#include <csignal>
#include <iostream>
#include <cstdlib>
class Tester {
    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";
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

[edit] See also

causes normal program termination with cleaning up
(function) [edit]
registers a function to be called on std::exit() invocation
(function) [edit]
causes quick program termination without completely cleaning up
(function) [edit]
registers a function to be called on quick_exit invocation
(function) [edit]
sets a signal handler for particular signal
(function) [edit]
C documentation for abort