__try
{
CString str="afd";
MessageBox(str.GetBuffer(0));
}
__finally
{
MessageBox("finally");
}
出现以下错误提示
warning C4509: nonstandard extension used: 'OnButton1' uses SEH and 'str' has destructor;Cannot use __try in functions that require object unwinding

解决方案 »

  1.   

    把 CString str挪到TRY的外面.
    SEH不允许在内部定义有析构函数的变量
      

  2.   

    CString str="afd";

    __try
    {
    MessageBox(str.GetBuffer(0));

    }
    __finally
    {
    MessageBox("finally");
    }同样错。
      

  3.   

    SEH里面只能用很简单的数据类型,比如 int, char[].char sz[32];
    strcpy( sz, "afd" );__try
    {
    MessageBox(sz);}
    __finally
    {
    MessageBox("finally");
    }
      

  4.   

    通过指针访问也不行。 CString *str= new CString("afd");

    __try
    {
    MessageBox(str->GetBuffer(0));

    }
    __finally
    {
    MessageBox("finally");
    delete str;
    }错误提示:Cannot use __try in functions that require object unwinding。Microsoft的try真是垃圾,远比不上delphi的try.
      

  5.   


    :) 这就是你无知了. __try 和 try 是不同的东西.__try 叫SEH, 结构化异常. 是捕捉系统异常用的.
      

  6.   

    根据你的用途分析, 你应该用 try
      

  7.   

    MSDN:
    ------------------------------
    Microsoft C++ supports two kinds of exception handling: C++ exception handling (try, throw, catch) 
    Structured exception handling (__try/__except, __try/__finally) 
    Although structured exception handling works with C and C++ source files, it is not specifically designed for C++. For C++ programs, you should use C++ exception handling.
    结构化异常不能出现在带有析构函数的C++程序里.例如:
    class CA
    {
    public:
    CA()
    {
    __try
    {
    }
    __finally
    {
    }
    } //~CA();
    };
    OK!----------------
    class CA
    {
    public:
    CA()
    {
    __try
    {
    }
    __finally
    {
    }
    } ~CA();
    };
    NOT OK!!!
      

  8.   

    delphi 的try...finaly可以支持放入任何东西,为何VC的__try,就那么小气,胃口这么小呢(连CString也吃不下),不知微软是扩展它,最终目的是什么...
      

  9.   

    __try 叫SEH, 结构化异常. 是捕捉系统异常用的.
    根据你的用途分析, 你应该用 try__try是用来捕捉 EnterCriticalSection 这种系统 API 所产生的异常的。delphi的try可以吗?