CHttpFile *file;
try
{
//
}catch(CException *e)
{
e->Delete();}
file->Close();//程序总是在这儿出错
delete file;

解决方案 »

  1.   

    CHttpFile *file = NULL;
    try
    {
    //
    }catch(CException *e)
    {
    e->Delete();}
    if (file)
    {
        file->Close();
        delete file;
    }
      

  2.   

    检查一下在出错的地方你的file指针是否指向正确的CHttpFile对象。
      

  3.   

    CHttpFile *httpfile=NULL;
    CInternetSession inetsession;
    try
    {
                      .......
    httpfile->Close ();
    delete []httpfile;
    // delete httpfile;
    inetsession.Close();
    }
    catch(...)
    {
    return -1;
    }
    可以放到try{}里试验一下,当然如果放在外面,检查一下httpfile==NULL?这样,就知道是否得到一个已经打开的httpfile
    另外delete [] httpfile;这样处理比较好
      

  4.   

    真是奇怪
    CHttpFile *file = NULL;
    try
    {
    //
    }catch(CException *e)
    {
    e->Delete();}
    if (file)//这样写就出错
    {
        file->Close();
        delete file;
    }
    if (!file)//这样写就不出错
    {
        file->Close();
        delete file;
    }明明file己经不为空了
      

  5.   

    CInternetSession::OpenURL
    Returns a file handle for FTP, GOPHER, HTTP, and FILE-type Internet services only. Returns NULL if parsing was unsuccessful.返回的是文件句柄,实际也就是一个可以指针了,成功了,那么自然非NULL,不成功,则是NULL你的调用,发生异常了吗,也就是
    catch{}执行到了吗?如果有Exception,httpfile指针指向的是否有效,不一定,如果try{}里都有异常,那么最好检查一下异常出现在什么地方另外判断的时候用if (file==NULL)