Thread View: comp.std.c++
1 messages
1 total messages
Started by Graham Dumpleton
Tue, 10 Oct 1995 02:25
Calling terminate() explicitly.
Author: Graham Dumpleton
Date: Tue, 10 Oct 1995 02:25
Date: Tue, 10 Oct 1995 02:25
54 lines
3557 bytes
3557 bytes
In 18.6.2.3 of the 28th April draft of the standard, it says for the terminate() function: Called by the implementation when exception handling must be abandoned for any of several reasons. This indicates that terminate() will be called by the implementation, however, it doesn't clearly state one way or the other whether user code can call terminate() directly as well. The problem is that in Sun C++ 4.0.1 (not the latest patch level though), if you call terminate() directly it generates a SEGV. The SEGV occurs even if you have supplied a terminate function using set_terminate() but before it might have called the supplied terminate function. Other C++ compilers supporting exceptions I have tried quite happily call the supplied terminate function and if it returns call abort(). Can someone give an indication as to whether user code is permitted to call terminate(). I cannot see any reason why user code should not be able to call it, after all, there are some situations where things have gotten so bad that you want to be able to stop the program without the chance of an exception handler stopping you from doing so. Yes, exit() could be called directly, but then I couldn't have any cleanup or restart actions as defined by the terminate function which has been registered using set_terminate() carried out. The only option if using exit() is to use the atexit() function, however, I would then have to register my terminate function in two places when I could get away with registering it just once with set_terminate(). There is also the problem that not all current systems have atexit(), or they have it under a different name, with it working in slightly different ways. I have also seen some compilers not even call the routines provided using atexit() (or similar function) due to the compiler implementation overriding the default implementation of exit(). Overall, it is much cleaner to have just one way of stopping the process, that is terminate(), whether it be called by the implementation code or user code. If someone is dealing with a compiler which doesn't support exceptions they can easily make their code upwardly compatable by providing their own version of terminate()/set_terminate(), use these and know that it will also work on a compiler which does support exceptions. The only thing which would need to be dealt with if calling of terminate() by user code is permitted, is what to do if the terminate function somehow called terminate() again. This is not much different than the terminate function somehow throwing another exception. I do not know how this might currently be dealt with in the standard. BTW, if someone can tell me that Sun C++ has already fixed the problem in a later version that would also be good. :-) -- Graham Dumpleton (grahamd@nms.otc.com.au) [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads