std::abort - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::abort

From cppreference.com
< cpp‎ | utility‎ | program

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

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

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

### [edit] Parameters

(none)

### [edit] Return value

(none)

### [edit] Exceptions

(none) | (until C++11)
`noexcept` specification: noexcept | (since C++11)

### [edit] 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

### [edit] See also

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

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/utility/program/abort&oldid=73442"
Category:

- unconditionally noexcept