-
January 15th, 2008, 02:46 PM #1
Correct exception handling syntax Win32
I'm writing an application (my first Win32 app) to connect to a MySQL database and query the database. I'm using the Mysql++ wrapper to connect my C++ code to the database. My program is functioning, and can connect to remote databases, etc except it was crashing when Mysql++ threw an exception error. I've since fixed the problem by handling the exceptions but wanted some opinions on my methods since this is the first time I've done this. I know my code *works* but I want to know if what I've done is a good approach to handling exceptions in Win32.
Here is my main program loop:
run is a bool that is defaulted to true. RunMessageLoop() is as you probably guessed my message loop, which returns a bool. If the WM_QUIT message is recieved the program exits. Is this the correct way to handle exceptions? Or am I doing it a backwards way? Any info would be greatly appreciated. Thanks!Code:while (run) { try { if (!RunMessageLoop())//Enter the message loop. run = false; break; } catch (std::exception& e) { ::MessageBox(NULL, e.what(), "Exception", 0); } }"There are only 10 kinds of people in the world, those that can read binary, and those that cannot."
-
January 16th, 2008, 12:31 PM #2
They key to exception handling is not to have just "generic" try/catchs in an attempt to avoid unhandled exceptions. They don't do anything but try to hide that your program is having issues

When using a try/catch, IMO, it should be around the offending code, that way when an exception is throw you know what went wrong as well as *how* to handle it.
If appears as if the RunMessageLoop function would be the one throwing the exception and I would put my exception handling code in there where the problems are. That way you can handle them appropriately when they occur.
JkrohnSignatures blow hard
If your signature contains an ad of any kind, congratulations, you're on my ignore list.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
MCI command handling window
By Nathan323 in forum Applications and Operating SystemsReplies: 3Last Post: August 4th, 2007, 02:14 PM -
exception handling in C#
By ShuckyD in forum Webmastering and ProgrammingReplies: 2Last Post: March 22nd, 2006, 11:16 AM -
Weird PHP handling error?
By JavaChicken in forum Webmastering and ProgrammingReplies: 1Last Post: May 22nd, 2003, 01:15 PM -
Decent ASP Error Handling
By Boba Fett in forum Webmastering and ProgrammingReplies: 0Last Post: March 20th, 2002, 07:03 AM



LinkBack URL
About LinkBacks




Reply With Quote


I think Chuckie should go to jail for slinging such obvious BS, lol . . .
Voter Suppression is Alive and...