Throwing an exception

I was just curious, when you throw an exception is a message box supposed to pop telling you there was a problem and give you the option to abort or continue running the program? I just finished up a project for school and whenever an invalid input is put into my program there is no message box, but it correctly handles the problem....
Not necessarily. If you try to cin an integer and you input a string literal, the stream will try to handle the input, often giving you garbage but not crashing. That's not necessarily an exception. In addition, if you throw an exception and the exception is caught, the way it's handled is up to the catch clause. Otherwise the prog will usually abort immediately.
Ok, so if I wanted an error messagebox to pop up with the option to abort or continue like I have seen previously what would I have to put in the catch block?
You can't make a new window with core C++. You need to use the API for your OS. However, you can check this article, which I believe could answer some of your questions over input control: http://www.cplusplus.com/forum/articles/6046/
closed account (1yR4jE8b)
Are you using Microsoft Visual C++? The Microsoft debugger will have a pop up window that the program crashed with an uncaught exception, but if you try to run the program by itself it probably wouldn't do that.

Program's compiled with g++ on windows will just crash and Windows itself will warn you that "This program was asked to exit in an unusual way, Windows is searching for a solution..." blah blah blah

In Linux, programs that crash with an uncaught exception will print the exception details to standard output in whatever terminal you run it from.

I have no idea with a Mac.
I am using microsoft visual C++...I haven't changed a thing so im assuming that i am using the microsoft debugger. Basically my program is a tic tac toe board and it throws exceptions when the user enters invalid data into the program such as picking a spot on the board that is already occupied. I have read a TON about exceptions now and I am still unclear exactly what should happen. When my program catches an exception it automatically outputs "invalid data, please enter a new number" This is exactly what I want my program to do, my question is whether or not I should get a pop up window telling me to break from the program or continue....because I saw a window like this on one of my instructors examples. I really don't want to go to school on Monday and turn in a malfunctioning program! If anyone knows, please let me know
closed account (1yR4jE8b)
Generally, there shouldn't be a popup window for console application. If your application handles the exception and just keeps going then it should be fine. Dialog boxes are annoying :P
haha, I agree.....Thanks!
You probably saw a message box that was intentionally called in a catch block; e.g. by
 
AfxMessageBox("Invalid data, please enter a new number.");

Then execution was returned back to input the number again. But, of course, you may terminate execution or do whatever you want.
Last edited on
Ah, I think you solved my problem...Thank you!
Topic archived. No new replies allowed.