简体   繁体   中英

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!?

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?

I think you should catch CInternetException* instead. For all MFC exceptions is throwed as a pointer.

PS. You should also use CException::Delete() in your catch block to delete the exception object you just catched if you don't need to throw it again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM