Why does my MFC app hang when I throw an exception?

后端 未结 3 1706
北荒
北荒 2020-12-18 10:35

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 on

3条回答
  •  爱一瞬间的悲伤
    2020-12-18 10:58

    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.

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

提交回复
热议问题