Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 595
  • Last Modified:

MFC Exception Handling - What happens to an uncaught exception thrown in an event-handler?

If an event handler throws an exception, and it is not caught by a programmer-defined try/catch block, is the event canceled?

In all cases, only in some?

Thanks
0
oxygen_728
Asked:
oxygen_728
1 Solution
 
AndyAinscowCommented:
I think an unhandled exception will always result in the program crashing, not the event being canceled.
0
 
sjith2000Commented:
If the unhandled exception occurs in the event handler, the application crashes and the message won't be removed from the message queue.
0
 
AndyAinscowCommented:
sjith2000 - please read the comments by other experts first.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sjith2000Commented:
Hi AndyAinscow,
  I am very glad to say that I had already seen the comment written by you.I also feel that the application will crash as you think.Also I feel that the message won't be removed from the message queue
0
 
oxygen_728Author Commented:
Thanks for the comments thus far,

I have had my suspicions that the application would crash.

I hope to test it soon.

Thanks for the input
0
 
AndyAinscowCommented:
To duplicate a previous experts comment with referring to it is not polite (or useful) behaviour.
If you agree with a comment posted earler then why not say so.
eg.
Andy is correct, the app will crash.
0
 
AndyAinscowCommented:
Give this a quick try.


add the folllowing class to a header file

class CTest {
public:
   CTest() {};
   ~CTest() {};
   const char *ShowReason() const {
      return "Exception in CTest class.";
   }
};


and to a button handler in an MFC based dialog app.
eg

void CxyzDlg::OnBnClickedButton1()
{
      throw CTest();
}


build in release mode and click on the button, watch the app crash.
0
 
itsmeandnobodyelseCommented:
>>>> I feel that the message won't be removed from the message queue
an exception is independent of the existence or non-existance of message queues. Exeption handling is realized by some kind of 'long jumps' along the call stack.

>>>> have had my suspicions that the application would crash.
What is the reason for your doubts. As Andy showed, it is simple to verify that unhandled exceptions lead to a crash.

Regards, Alex
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now