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

今天在写一个控制台程序。按照以前的经验,输入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.

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值