+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Senior Member BattleToad's Avatar
    Join Date
    Aug 2004
    Location
    Virginia Beach, Va
    Posts
    603

    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:
    Code:
    while (run)
    {
    	try
    	{
    		if (!RunMessageLoop())//Enter the message loop.
    			run = false;
    			break;
    	}
    	catch (std::exception& e)
    	{
    		::MessageBox(NULL, e.what(), "Exception", 0);
    	}
    }
    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!
    "There are only 10 kinds of people in the world, those that can read binary, and those that cannot."

  2. #2
    Real gangstas sip on Yacc jkrohn's Avatar
    Join Date
    Oct 2001
    Location
    Suckas-ville
    Posts
    4,554
    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.

    Jkrohn
    Signatures 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

  1. MCI command handling window
    By Nathan323 in forum Applications and Operating Systems
    Replies: 3
    Last Post: August 4th, 2007, 02:14 PM
  2. exception handling in C#
    By ShuckyD in forum Webmastering and Programming
    Replies: 2
    Last Post: March 22nd, 2006, 11:16 AM
  3. Weird PHP handling error?
    By JavaChicken in forum Webmastering and Programming
    Replies: 1
    Last Post: May 22nd, 2003, 01:15 PM
  4. Decent ASP Error Handling
    By Boba Fett in forum Webmastering and Programming
    Replies: 0
    Last Post: March 20th, 2002, 07:03 AM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews