为什么我的MFC应用程序挂起,当我抛出异常? [英] Why does my MFC app hang when I throw an exception?

查看:112
本文介绍了为什么我的MFC应用程序挂起,当我抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在MFC对话框中抛出异常,应用程序将挂起,即使您的代码中有catch块。它拒绝响应鼠标或键盘,关闭它的唯一方法是使用任务管理器。

If you throw an exception from inside an MFC dialog, the app hangs, even if you have a catch block in your code. It refuses to respond to the mouse or keyboard, and the only way to shut it down is to use Task Manager.

我的耻辱,有一个流行的收缩包装应用程序,挂起每次遇到一个特殊的错误在模态对话框。当我们从整数错误代码到异常,我负责选择std :: exception作为抛出的异常的基类。直到大量的工作进入转换,我们的测试发现了这个问题,到那时为止已经太晚了。

To my shame, there is a popular shrink-wrapped application that hangs every time it encounters an exceptional error in a modal dialog. When we made a massive shift from integer error codes to exceptions, I was responsible for choosing std::exception as the base class for the thrown exceptions. It wasn't until a huge amount of work went into the conversion that our testing uncovered this problem, and by then it was too late to change. Hopefully this question/answer will keep someone from making the same mistake.

推荐答案

CDialog :: DoModal的代码使对话框模态通过禁用父窗口。当对话框代码返回时,窗口被重新启用。对于CException *错误有一个显式捕获,但不是任何其他类型的抛出异常;

The code for CDialog::DoModal makes the dialog modal by disabling the parent window. When the dialog code returns, the window is reenabled. There is an explicit catch for CException* errors, but not for any other kind of thrown exception; thus the parent window never gets reenabled.

更改您的代码以抛出一个指向CException派生的任何异常的指针,你会解决这个问题。

Change your code to throw a pointer to any exception derived from CException, and you'll fix the problem.

这篇关于为什么我的MFC应用程序挂起,当我抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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