http://spiff.tripnet.se/~iczelion/Exceptionhandling.html
记得有书上说过,如果你的程序破坏了堆栈(或许是其他导致不能继续执行下去的数据结构),系统会直接关闭你的程序

解决方案 »

  1.   

    一般是内存溢出造成的。仔细检查你的程序。特别是内存分配,sprintf strcpy memcpy等语句
      

  2.   

    多线程长时间运行的程序,应该分配一个大的缓冲池,每次内存分配用静态指针的方式进行。也就是说尽可能的只用一次NEW。其他的分配应在缓冲池中进行
      

  3.   

    内存溢出算异常吧,应该可以捕获啊。
    另外那台机器是2cpu的有没有关系?我想知道有什么是__try捕获不到的?
      

  4.   

    我的线程是经常new结构来互相传递信息,用完后便delete.你讲的大的缓冲池是什么概念能详细说说吗?(最好给个简单的例子说明)以及为什么要这样做,不胜感激!!
      

  5.   

    只要是本线程中的错误,比如内存益处,/0
    _try{
    }
    _except(...){
    }
    都可以截获,不能截获的是
    1,其他线程的错误,比如CSocket会创建新的线程,捕获不到。
    2,MFC的某些抛出的异常捕获不到。
    3,COM的异常通常不能通过该方式捕获
    4,new 的内存使用超界,delete导致的异常。
      

  6.   

    to lhj
    1:我的程序没有使用CSocket,用的是api函数
    2:lhj:能否举个mfc抛出的__try __except捕获不到的异常的例子,我想做个实验以验证。
    3:我没有用到COM
    4: 给个例子好吗,我非常需要。
    谢谢!
      

  7.   

    4G的虚拟内存也会因为碎片过多而崩溃.何况你的程序还只能是 使用1G
    new的分配是在应用程序堆上分配的.你即是网络游戏,那么字符串可以放在字符缓冲池中. (见数据结构).而其他的固定大小的数据.比方可能要用到500个用户的数据.则可以在程序启动时分配一个1000 个单元的数组,建立空闲单元的索引, 每次从中 取一个存放.不要 想到什么时候要内存了就用NEW去分配.而且你最好不要用NEW.用HeapAlloc或者GlobalAlloc分配可移动内存.这些内存是系统可移动的,从 而避免碎片出现.只是使用时比较麻烦,要先锁定. 可以看< WINDOWS核心编程>
      

  8.   

    #include <stdio.h>
    int main()
    {
     char szBuff[1];
     for(char *pBuff = szBuff;;pBuff++)
      *pBuff = '$';
     printf("I'll never reach Here !!\n");
     return 0;
    }when run in a debugger gives the following error:
    Unhandled exception in test1.exe: 0xC0000005: Access Violation
    But does not display any sort of exception when run
    outside a debugger and crash directly.The system depends on information saved on the stack to unwind exceptions;
    as the whole stack is trashed in this case, attempting to call the default
    handler (which would display the error message box, and optionally attach a
    debugger) will only result in a new exception, upon which the program will
    be terminated immediately.Under a debugger however, the system will suspend the program and notify the
    debugger, giving it a chance to deal with the problem first.
    #include <stdio.h>
    int main()
    {
     char szBuff[1];
     for(char *pBuff = szBuff+1024;;pBuff++) // added the +1024
      *pBuff = '$';
     printf("I'll never reach Here !!\n");
     return 0;
    }and I got these 2 errors...
    The instruction at "0x0040b4cf" referenced memory at "0x00133000". The
    memory could not be written
    &&
    The instruction at "0x77f84abe" referenced memory at "0x24242430". The
    memory could not be read
    That little jump ahead saved part of the stack !
      

  9.   

    to masterz():
    你给出的第一个例子确实捕获不到,非常感谢!
    可是我如何在茫茫的代码中找到那条出错的语句。
    有什么快捷的调试方法?望赐教。
      

  10.   

    怎样捕获#include <stdio.h>
    int main()
    {
    char szBuff[1];
    for(char *pBuff = szBuff;;pBuff++)
      *pBuff = '$';
    printf("I'll never reach Here !!\n");
    return 0;
    }的异常?0xC0000005无法捕获吗?
      

  11.   

    我在编写服务器程序的时候也出现这种情况过,我也是用学日志的形式来调试,没什么反映的就退出了。后来一次偶然的机会发现一个内存溢出的错误修改后就没有再出现突然退出的情况。我也说不出什么原因,windows核心中好像有说过,当内存溢出时会访问一个专门的区域,从而引发访问违规,系统不进行提示的,程序就退出了。
      

  12.   

    masterz真是厉害,都两个星星了。