控制台程序输入CTRL+C后弹出异常的原因

来源:互联网 发布:文件上传js代码 编辑:程序博客网 时间:2024/05/16 12:20

今天在写一个控制台程序。按照以前的经验,输入CTRL+C后,程序应该正常结束,

但是今天却每次都弹出一个异常提示框,“0x40010005: Control-C”。

排查了很长时间,终于找到原因了。

实际上这不是什么错误,只要在Debug模式下,输入CTRL+C或者CTRL+BREAK等命令

都会导致系统内部抛出一个异常;在非Debug模式下,系统内部不会抛出这个异常。

参考资料在这里:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682541(v=vs.85).aspx

The CTRL+C and CTRL+BREAK key combinations receive special handling by console processes. By default, when a console window has the keyboard focus, CTRL+C or CTRL+BREAK is treated as a signal (SIGINT or SIGBREAK) and not as keyboard input. By default, these signals are passed to all console processes that are attached to the console. (Detached processes are not affected.) The system creates a new thread in each client process to handle the event. The thread raises an exception if the process is being debugged. The debugger can handle the exception or continue with the exception unhandled.

原创粉丝点击