How to catch the Control-C exception in a Visual C++ console app?

守給你的承諾、 提交于 2019-12-10 13:48:49

问题


This seems like it ought to be simple, but I've tried both
try {} catch (...) {} C++ exception handling and
__try {} __finally {} structured exception handling (SEH)
and neither one will catch the exception that happens when you Control-C the application.

I didn't really expect C++ exception handling to do this, since the Control-C is a system-type signal and not caused by a C++ throw(), but I tried it anyway when SEH didn't work.

If I run under a debugger, it shows that Control-C raises a first-chance exception, but when it's rethrown, my handler is never invoked.


回答1:


Here is how to handle an interrupt in Win32.

http://msdn.microsoft.com/en-us/library/ms686016%28VS.85%29.aspx



来源:https://stackoverflow.com/questions/1151183/how-to-catch-the-control-c-exception-in-a-visual-c-console-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!