开发者

catch exception in mfc callback function

开发者 https://www.devze.com 2023-01-10 02:41 出处:网络
I\'m using vc2008, writing some MFC code, I add a button, double click it, and vc2008 开发者_开发问答automatically create a callback function for me, and my code is like this:

I'm using vc2008, writing some MFC code, I add a button, double click it, and vc2008 开发者_开发问答automatically create a callback function for me, and my code is like this:

void CDeviceTesterDlg::OnBnClickedButton1()
{
    try {
        ....
    } catch (std::exception &e) {
        ....
    };
}

the problem is, I need place this ugly code in every OnBnClickedButtonXXX function, are there any good method only place the code in one place?

A example in PyQt, I use this method:

def excepthook(type, value, traceback):
    QMessageBox.warning(None, "", "%s: %s" % (str(type), str(value)))
    return sys.__excepthook__(type, value, traceback)
sys.excepthook = excepthook


You can try using Structured Exception Handling. This is not equivalent to try/catch but it's similar to your PyQt example.

0

精彩评论

暂无评论...
验证码 换一张
取 消