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.
精彩评论