?
Solved

How to catch  AfxThrowInternetException?

Posted on 2006-06-05
5
Medium Priority
?
824 Views
Last Modified: 2013-11-20
hi, everybody,
   When I looked for some information in MSDN about CInternetSession::CInternetSession, there's a sentence: " If no Internet connection can be opened, CInternetSession throws an AfxThrowInternetException."
   The prototype is :
   void AFXAPI AfxThrowInternetException(DWORD dwContext, DWORD dwError = 0);

   How to catch the exception?

thanks!
0
Comment
Question by:tzk
  • 2
  • 2
5 Comments
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 150 total points
ID: 16831259
try
{
....
}
catch(CInternetException* e)
{
e->ReportError();
e->Delete();
}
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16831291
This is CInternetSession cosntructor which throws exception :

CInternetSession::CInternetSession(LPCTSTR pstrAgent /* = NULL */,
        DWORD dwContext /* = 1 */,
        DWORD dwAccessType /* = PRE_CONFIG_INTERNET_ACCESS */,
        LPCTSTR pstrProxyName /* = NULL */,
        LPCTSTR pstrProxyBypass /* = NULL */,
        DWORD dwFlags /* = 0 */)
{

   ......
   ......

m_hSession = InternetOpen(pstrAgent, dwAccessType, pstrProxyName, pstrProxyBypass, dwFlags);


        if (m_hSession == NULL)
                AfxThrowInternetException(m_dwContext);
        else
            .....

}

You may catch that using CInternetException like :

try
{
..
}
catch (CInternetException* pEx)
 {
  pEx->ReportError();
  pEx->Delete();
 }


-MAHESH
0
 

Author Comment

by:tzk
ID: 16831406
I'm confused. When creating an instance " CInternetSession session_1;", no connection is built. So, Creating an instance isn't any exception, is it?
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 16831435
As I posted earlier
try
{
// do your stuff here
}
catch(CInternetException* e)
{
//if a CInternetSession exception was thrown then this code block will execute
e->ReportError();
e->Delete();
}
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16831720
>>When creating an instance " CInternetSession session_1;", no connection is built. So, Creating an instance isn't any exception, is it?

May be overloaded constructor that have parameters only throws exception.. empty constructor not throwing exception...

-MAHESH
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question