Why does a C ++ call at runtime call terminate() ? He does not do this at random or because of circumstances that cannot be determined and / or avoided when the code is written. This is because your code is executing what is defined to call the terminate() call, for example, throwing an exception from the destructor while unwinding strings.
The C ++ standard has a list of all situations that are defined to call the terminate() call. If you do not want terminate() called, do not do any of this in your code. The same goes for unexpected() , abort() , etc.
I don’t think this is really different from the fact that you need to avoid undefined behavior or to avoid code spelling altogether. You should also avoid behavior that is defined, but undesirable.
Perhaps you have a specific example where it is difficult to avoid calling terminate() , but an exception from the destructor when unpacking the stack excludes it. Just don't throw exceptions from destructors, never. This means that you are designing your destructors so that if they do something that might fail, the destructor catches an exception and your code continues in a certain state.
There are several situations where your system will powerlessly crack your lap process because of what your C ++ code is doing (though not by calling terminate() ). For example, if the system is excessive memory, and VMM cannot run promises malloc/new , then your process may be killed. But this is a system function and probably applies equally to another language that your C ++ calls. I don't think you can (or should) do anything if your caller knows that your library can allocate memory. In this case, this is not your code error, the process has died, it is a certain response of the operating system to conditions with low memory.
Steve jessop
source share