如何在Visual C ++控制台应用程序中捕获Control-C异常? [英] How to catch the Control-C exception in a Visual C++ console app?

查看:165
本文介绍了如何在Visual C ++控制台应用程序中捕获Control-C异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎应该很简单,但我已经尝试过

try {} catch(...){} C ++异常处理和

__ try {} __finally {} 结构化异常处理(SEH)

,都不会捕获异常当您使用Control-C应用程序时,会发生。

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.

我并没有真正期望C ++异常处理这样做,因为Control-C是系统类型的信号,而不是由C ++ throw()引起的,但是当SEH不工作时,我尝试过。

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.

如果我在调试器下运行,则表明Control-C引发了第一次机会异常,但是当它被重新抛出时,我的处理程序永远不会被调用。

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.

推荐答案

这里是如何处理Win32中的中断。

Here is how to handle an interrupt in Win32.

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

这篇关于如何在Visual C ++控制台应用程序中捕获Control-C异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆