std::abort (3) - Linux Manuals
std::abort: std::abort
Command to display std::abort
manual in Linux: $ man 3 std::abort
NAME
std::abort - std::abort
Synopsis
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.
Parameters
(none)
Return value
(none)
Exceptions
(none)
Notes
POSIX specifies that the abort() function overrides blocking or ignoring the SIGABRT signal.
Example
// 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";
}
Output:
Tester ctor
Tester ctor
SIGABRT received
See also
causes normal program termination with cleaning up
exit (function)
registers a function to be called on std::exit() invocation
atexit (function)
quick_exit causes quick program termination without completely cleaning up
(function)
(C++11)
at_quick_exit registers a function to be called on quick_exit invocation
(function)
(C++11)
sets a signal handler for particular signal
signal (function)
Pages related to std::abort
- std::abs(float),std::fabs,std::fabsf,std::fabsl (3) - std::abs(float),std::fabs,std::fabsf,std::fabsl
- std::abs(std::complex) (3) - std::abs(std::complex)
- std::abs(std::valarray) (3) - std::abs(std::valarray)
- std::abs,std::labs,std::llabs,std::imaxabs (3) - std::abs,std::labs,std::llabs,std::imaxabs
- std::accumulate (3) - std::accumulate
- std::acos(std::complex) (3) - std::acos(std::complex)
- std::acos(std::valarray) (3) - std::acos(std::valarray)
- std::acos,std::acosf,std::acosl (3) - std::acos,std::acosf,std::acosl
- std::acosh(std::complex) (3) - std::acosh(std::complex)
- std::acosh,std::acoshf,std::acoshl (3) - std::acosh,std::acoshf,std::acoshl