Quote:Original post by DrathisQuote:Original post by voguemaster
Its true that hardcore engine dev guys will stone you for even considering using exceptions but maybe this is an exception :)
Why would they stone you? What is wrong with exceptions?
There is nothig 'wrong' with exceptions but using them for this is the kind of thing people try to push against; exceptions are for exceptional situations, the kind of thing which shouldn't occur in normal operation but might and you want to handle gracefull. The clue is in the name really.
Exiting from a game is not, by any definition, an exceptional event which is why they are the wrong tool for the job.
Calling 'exit' would do nicely, as would posting the correct window message to shut down; how you get your game to call exit however is another matter but most likely you would have the code which handles any 'I want to exit' events call one central 'shut down' function and that does the Right Thing(tm) such as terminate message loops, close down threads, stop tasks or simply call 'exit' and let things die.
There is no good reason to use exceptions for this, doing so is just abusing them. Heck, its not even like you have to handle it from multiple points;
- alt-f4 handler on windows
- exit options from your GUI code
- clicking 'close window' button in windowed mode.
Not the most taxing of things to handle...