c++exceptionconnectionopenurl

Throwing CInternetException for error 12029


This somewhat links to my previous question. Background details here: Simple HTTP request with C++

Basically I am sending data to a server through an URL with C++. I am now using openURL() function in the CInternetSession class to do it. If the openURL connects to the server successfully, no errors or exceptions are thrown. However, sometimes, in the debugger in Visual C++ 2006, I would get this pop-up

First-chance exception in myProg.exe (KERNELBASE.DLL): 
0xE06D7363: Microsoft C++ Exception.

I have set the debug exceptions to "stop always" and in the debug window it shows me

Warning: throwing CInternetException for error 12029

In addition, when I run the program by itself (without the debugger and stuff), I get a pop-up saying debug error.

I understand that this is because the openURL() couldn't make a connection to the specified URL. However, my problem now is I do not want a pop-up to inform me of this. I have put a try catch block around my code but it's still not handling the exception. Here's the code

    try {
        // Open HTTP file
        pHttpFile =(CHttpFile *) mySession.OpenURL(test1.c_str());
    }
    catch (CInternetException) {
        printf("Received Exception from OpenURL()");
        // Handle exception
    }

Am I missing something here!?


Solution

  • Try connecting to that IP address with another method manually with 'connect'. If you can connect to it, then the openURL won't throw an exception because you already tested that you can connect to it with that other function I just mentioned.

    May you also consider looking in your code to ensure that the exception is not being thrown elsewhere?