C++: continue after __debugbreak(), or better alternative
I am developing a C++ library with Visual Studio, and there are points in my code where some conditions are checked. If such conditions fails, an exception is thrown. In order to aid my debugging, I have put a
__debugbreak();
statement (like asm int 3;) before the point at which the exception is thrown, which effectively invoke the debugger (or point the existing debugger) to the incriminated line stopping execution, so I can have a look at variables, call stack and so on...
However, at times I may just want to continue execution (like if __debugbreak();) was not present and just throw the exception (which log the error开发者_StackOverflow社区s and do some other stuff).
The issue is that (running outside the debugger) I am just presented with a windows stating that the program has crashed, and choose between closing it or debugging it. What I would like to achieve is a choice between debugging (i.e. attach the debugger, point to line, break execution) and continuing execution.
How to do this?
It seems like a much better option than using this particular library function would be to just run the program in a debugger and put breakpoints at the spots in which you want to pause execution for testing. Hardcoding in interrupts to trap into the debugger means that you might accidentally release code to clients that has debugging hooks still in it, and also gives you a much less fine-grained control over when and how you stop execution and start debugging.
Use the _ASSERT and _ASSERTE macros in the Microsoft C Runtime.
精彩评论