如int a[3];
TRY
{              for(int i=0;i<5;i++)
                     a[i]=0;
}
CATCH(CException, e)
{
char szBuf[100];
e->GetErrorMessage(szBuf,100);
strcat(szBuf,"\n - caught error");
AfxMessageBox(szBuf);
e->Delete();
}
END_CATCH
为何CATCH不着溢出错误

解决方案 »

  1.   

    现有的C/C++编译器不会做溢出检查,建议用第三方工具:
    吐血推荐Compuware Numega BoundsChecker
      

  2.   

    现在要靠程序员的大脑:-),除非借助工具,这种问题很麻烦,没办法,谁叫我们用C/C++呢。
    所以很多人用Java/C#了。
      

  3.   

    template<typename T, int size>
    class simple_array
    {
    public:
        T m_array[size];
        T& operator[] (unsigned int pos) 
        {
            assert(pos < size); 
            return m_array[pos]; 
        };
    }