Structed Exception Handler 学习总结(一)

1. 在结构化异常处理中__try块和__except块是成对出现的,每一个__except块都必须有与之对应的__try块,不可能出现一个__try块下面有多于一个的__except块,如果这样就会出现编译错误,例如:

   __try 
    {
        *presult = d1 / d2;
    }
    __except(GetExceptionCode() == EXCEPTION_STACK_OVERFLOW ?
                EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
    {
        _tprintf(TEXT("stack overflow."));

    }
    __except(GetExceptionCode() == EXCEPTION_INT_DIVIDE_BY_ZERO ? 
                EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
    {
        return FALSE;
    }

试图编译以上代码,就会出现以下异常:

2.SEH中的__except子句括号中的表达式(也称为filter expression)在__try块发生异常时会被求值(evaluated,被计算)

以上论述表明了__except中的 fileter expression 的用法。

3.GetExceptionInformation和GetExceptionCode的使用

GetExceptionInformation:

GetExceptionCode:

posted @ 2013-10-19 19:24  a ray of sunshine  阅读(177)  评论(0编辑  收藏  举报