简体   繁体   English

为错误 12029 抛出 CInternetException

[英]Throwing CInternetException for error 12029

This somewhat links to my previous question.这有点链接到我之前的问题。 Background details here: Simple HTTP request with C++此处的背景详细信息: 使用 C++ 的简单 HTTP 请求

Basically I am sending data to a server through an URL with C++.基本上,我使用 C++ 通过 URL 将数据发送到服务器。 I am now using openURL() function in the CInternetSession class to do it.我现在在 CInternetSession 类中使用 openURL() 函数来做到这一点。 If the openURL connects to the server successfully, no errors or exceptions are thrown.如果 openURL 成功连接到服务器,则不会抛出任何错误或异常。 However, sometimes, in the debugger in Visual C++ 2006, I would get this pop-up但是,有时,在 Visual C++ 2006 的调试器中,我会看到这个弹出窗口

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.我知道这是因为 openURL() 无法连接到指定的 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.我在我的代码周围放置了一个 try catch 块,但它仍然没有处理异常。 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'.尝试使用“connect”手动使用另一种方法连接到该 IP 地址。 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.如果您可以连接到它,那么 openURL 不会抛出异常,因为您已经测试过可以使用我刚刚提到的其他功能连接到它。

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.我认为您应该改为捕获 CInternetException*。 For all MFC exceptions is throwed as a pointer.对于所有 MFC 异常都作为指针抛出。

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.如果您不需要再次抛出它,您还应该在 catch 块中使用 CException::Delete() 来删除刚刚捕获的异常对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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