Throwing exceptions that will be caught in the main and then thrown means that your RAII resource objects will be cleared. On most systems, this is not required for a large number of resource types. The OS will clear memory, file descriptors, etc. (Although I used a system in which the lack of free memory meant that it remained allocated until the system rebooted, so a leak on the program output was not a good idea.)
But there are other types of resources that you might want to release clean, such as connecting to a network or database, or a mechanical device that you control, and you need to safely disconnect it. If an application uses a lot of these things, you might prefer an exception to restore the original stack and exit.
Thus, the appropriate exit method is application dependent. If the application knows this safely, then calling _Exit (), abort (), exit (), or quickexit () can be perfectly reasonable. (The library code should not call them, because obviously the library does not know whether it will be safe for every application that will ever use the library.) If there is any critical cleanup that must be performed before the application exits, but you know that it is limited, the application can register this cleanup code through atexit () or at_quick_exit ().
So, basically decide what you need to clean, document, put in it and try to make sure that it is tested.
bames53
source share