Namespaces
Variants

std::quick_exit

从 ko.cppreference.net
 
 
 
 
定义于头文件 <cstdlib>
[[noreturn]] void quick_exit( int exit_code ) noexcept;
(C++11 起)

导致正常的程序终止发生,而不完全清理资源。

传递给 std::at_quick_exit 的函数按照其注册顺序的逆序被调用。如果任何函数中有异常试图传播出去,则会调用 std::terminate。在调用已注册函数之后,调用 std::_Exit(exit_code)。

传递给 std::atexit 的函数不会被调用。

매개변수

exit_code - 프로그램의 종료 상태

예제

#include <cstdlib>
#include <iostream>
template<int N>
void quick_exit_handler()
{
    std::cout << "quick_exit handler #" << N << std::endl; // flush is intended
}
void at_exit_handler()
{
    std::cout << "at_exit handler\n";
}
int main()
{
    if (std::at_quick_exit(quick_exit_handler<1>) ||
        std::at_quick_exit(quick_exit_handler<2>))
    {
        std::cerr << "Registration failed\n";
        return EXIT_FAILURE;
    }
    std::atexit(at_exit_handler); // the handler will not be called
    struct R { ~R() { std::cout << "destructor\n"; } } resource;
    /*...*/
    std::quick_exit(EXIT_SUCCESS);
    std::cout << "This statement is unreachable...\n";
}

출력:

quick_exit handler #2
quick_exit handler #1

참고 항목

비정상적인 프로그램 종료를 유발합니다 (정리 작업 없음)
(함수)
정리 작업과 함께 정상적인 프로그램 종료를 유발합니다
(함수)
std::exit() 호출 시 실행될 함수를 등록합니다
(함수)
std::quick_exit 호출 시 실행될 함수를 등록합니다
(함수)
C 문서 for quick_exit