SEHとminidump


http://msdn.microsoft.com/en-us/library/s58ftw19(v=vs.80).aspx
The follwing syntax describes a try-except statement:
__try 
{
   // guarded code
}
__except ( expression )
{
   // exception handler code
}

Remarks
The try-except statement is a Microsoft extens to the C and C+langages that enables taget appications to gain control when events that normalite program execution occur.Such events are careed exceptions,and the medeptextratonit
For related information、see the try-finally statement.
Exceptions can be einther handware-based orソフトware-based.Even when appration s cannot cover from handware or software exceptions,structred exception handling makes it possible to display error information and trap the internal state of the appration to help diagnose the problem.This especially useful for intermittent probles.cant probles.
Noteノート
Structured exceptionion handlining works with Win 32 for both C and C+source files.However、itisisisisnot speciilialallydesigned forC+.You can ensure thththththththyourcode ismoricode more popotablblblblblble byAltablble Alusing BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBgrams,it is recommanded that you you use the C++exception-handling mechansism(try、catch、and throw statements.
The compund statement after the __try clause is the body or garded section.The compund statement after the __except clause is the exception handler.The handler specifies a set of actions to be taken if an exception is rased during exection of the body section.Execution proceeds as follows:
  • The gurded section is executed.
  • Ifのexception occurs during execution of the Graded section、execution contions the statement after the __except clause.
  • If an exception occurs during execution of the Graded section or in in any routine the garded section cals,the __except expression (caled the filterexpression)is evaluated and the value determines how the exception is handed.The re re re three values:EXCEPTION_CONTINUE_EXECUTION(–1)   Exception is disyssed.Continue execution at the point where the exception occurred.EXCEPTION_CONTINUE_SEARCH(0)   Exception is not recognized.Continue to search up the stack for a handler,first for containing try-exceptstatements,then for handles with the next highest precedence.EXCEPTION_EXECUTE_HANDLER(1)   Exception is recognized.Transfer control to the exception handler by executing the __except compund statement、then continue execution after the __except block.
  • Because the_uexcept expression is evaluated as a C expressition、it is limited to a single value、the conditionl-expressition operator、or the commamation.If more extension processing is required、the expression can can can cal routinessition cation able the ables thereturne of.
    Eachアプリcan have its own exception handler.
    It is not valid to jump into a __try statement、but valid to jump out of one.The exception handler is not caled if a process is terminated in the middle of executing a try-except statement.
    For more information、see Knowledge Base article Q 315937:HOW TO:Trap Stock Overflow in a Visual C+Apple.
    Structured Exception Handling Intrinic Functions
    Structured exception handling provides two intrinic functions that are available to use with the try-except statement: Get Exception Code and Get Exception Information.
    Get Exception Code returns the code(a 32-bit integer)of the exception.
    The intrinic function Get Exception Information returns a pointer to a structure containing additional information about the exception.Through this pointer,you can access the machine state that existed the time of a handware exception.The struction struction
    struct _EXCEPTION_POINTERS {
          EXCEPTION_RECORD *ExceptionRecord,
          CONTEXT *ContextRecord }
    
    The pointer types_EXCEPTION_RECORD and_CONTEXT are defined in the include file EXCPT.H.
    You can use Get Exception Code within the exception handler.However,you can use Get Exception Information only within the exception filter expressition.The information it points to is generation on the stack and isのlonger available when control is tranferred to the exception handler.
    The intrinic function AbnormalTermination is available within a termination handler.It returns 0 if the body of the try-finally statement terminates sequentially.In all other cases,it returns 1.
    EXCPT.H defines some alternames for these intrinics:
    Get Exception Code is equivalent to_exception_コード
    Get Exception Information is equivalent to_exception_info
    AbnormalTermination is equivalent to_abnormaltermination

    Example
    //exceptions_try_except_Sttement.cpp
    //Example of try-except and try-finally statements
    ヽoo.ツ...........................................................
    萼include/for EXCEPTION_ACCESS_VIOLSION
    萼include
    int filter(unsigned int code,struct EXCEPT IONuPOINTERS*ep){
       puts("in filter.")
       if(code==EXCEPTIONUACCESSION){
          putts(“caught AV as expected.”);
          return EXCEPT IONUEXECUTEuHANDLER;
       }
       else{
          putts("didn't catch AV,unexpected.")
          return EXCEPT IONuCONTINUHUEUHu SEARCH;
       };
    )
    int main()
    {
       int*p=0 x 0000   //pointer to NULL
       puts("hello")
       __try{
          puts("in try")
          __try{
             puts("in try")
             *p=13;    //causes an access violation exception;
          }__finally{
             puts("in finally.termination:")
             putts(AbnormalTermination()?「\tabnormal」:「\tnormal」)
          }
       }__except(filter(GetException Code){
          puts(「in except」)
       }
       puts(「world」)
    )
    Output
    hello
    in try
    in try
    in filter.
    caught AV as expected.
    in finally. termination:
            abnormal
    in except
    world