问题
This seems like it ought to be simple, but I've tried bothtry {} 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