《C ++ programming specificationsArticle 51st: destructor, deallocation, and swap never fail.
I tried it today.
Today, I wrote a small program for my experiments. I checked every system call in the program. Once the call fails, a custom exception is thrown. At last, the main function captures all exceptions, then, output a friendly error message to the terminal.
After four or five hours of running the program, a dialog box is displayed, saying, "The xxx program has stopped working. Windows is checking the solution to this problem... "then asked me if I want to debug the program or cancel it. The terminal did not output any error messages that I prepared in advance.
Strange. This is generally caused by memory access exceptions, and my program does not have any array or pointer operations at all.
After a long time, I really clicked the "debug" button in the dialog box and opened Visual Studio to debug a lot of assembly code. Fortunately, although the program is built into the release version, you can still see the original C ++ code and runtime stack in Visual Studio after clicking "debug. Finally, we found that a system call failed while the program was running. My code failed to check and throw my custom exception. When the program throws an exception and performs stack unwinding, an object in the stack also throws an exception during the analysis. The class that the object has is defined by myself, and its destructor will also call a system function-of course, I also checked this system call, when an error occurs, the custom class is also thrown. Therefore, according to section 15.5.1 of the c ++ standard:
If a destructor called during stack unwinding exits with an exception,STD: TerminateIs called.
If an destructor throws an exception during stack rollback, the program will call STD: terminate.
What is the effect of calling STD: Terminate? As mentioned above.
Now you have to run the program for another few hours to know which system call went wrong.
This scene is a good explanation of what it means: "If you don't listen to the old man, you will suffer losses ."