• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 892
  • Last Modified:

How to catch AfxThrowInternetException?

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
tzk
Asked:
tzk
  • 2
  • 2
1 Solution
 
AndyAinscowFreelance programmer / ConsultantCommented:
try
{
....
}
catch(CInternetException* e)
{
e->ReportError();
e->Delete();
}
0
 
mahesh1402Commented:
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
 
tzkAuthor Commented:
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
 
AndyAinscowFreelance programmer / ConsultantCommented:
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
 
mahesh1402Commented:
>>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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now