例外フィルター(SEHもどき)

  • デル株式会社
  • 前回続き

    説明いらないかな

    // 例外フィルター設定
    SetUnhandledExceptionFilter(ExceptionFilter);

    LONG CALLBACK ExceptionFilter(EXCEPTION_POINTERS *ExceptionInfo)
    {
         BTCfj_FLogOutput(CFJ_LIB_BTCNF,CFJ_LVL_NEG,"ExceptionFilter() START (GetLastError = [%d])",::GetLastError());

         //////////////////////////////////////////////////////////////////////
         // 情報収集
         //////////////////////////////////////////////////////////////////////
         CString csExceptionRecordInfo;
         csExceptionRecordInfo = "例外フィルター";
         csExceptionRecordInfo += "\r\n";
         csExceptionRecordInfo += "** ExceptionFilter ExceptionRecord Info **";
         csExceptionRecordInfo += "\r\n";

         // 例外コードと内容
         CString csExceptionCode;
         csExceptionCode.Format("ExceptionCode : 0x%08x", ExceptionInfo->ExceptionRecord->ExceptionCode);
         csExceptionCode += "\r\n";
         switch(ExceptionInfo->ExceptionRecord->ExceptionCode)
         {
         case EXCEPTION_ACCESS_VIOLATION:
             csExceptionCode += "The thread tried to read from or write to a virtual address for which it does not have the appropriate access.";
             csExceptionCode += "\r\n";
             csExceptionCode += "スレッドが適切なアクセス権を持たない仮想アドレスに対して、読み取りまたは書き込みを試みました。";
             break;
         case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
             csExceptionCode += "The thread tried to access an array element that is out of bounds and the underlying hardware supports bounds checking.";
             csExceptionCode += "\r\n";
             csExceptionCode += "スレッドが範囲外の配列要素にアクセスしようとしました。使用中のハードウェアは境界チェックをサポートしています。";
             break;
         case EXCEPTION_BREAKPOINT:
             csExceptionCode += "A breakpoint was encountered.";
             csExceptionCode += "\r\n";
             csExceptionCode += "ブレークポイントに到達しました。";
             break;
         case EXCEPTION_DATATYPE_MISALIGNMENT:
             csExceptionCode += "The thread tried to read or write data that is misaligned on hardware that does not provide alignment. For example, 16-bit values must be aligned on 2-byte boundaries; 32-bit values on 4-byte boundaries, and so on.";
             csExceptionCode += "\r\n";
             csExceptionCode += "境界整列をサポートしないハードウェア上で、スレッドが境界に整列していないデータの読み取りまたは書き込みを試みました。たとえば、16 ビットの値は 2 バイトの境界線上に、32 ビットの値は 4 バイトの境界線上に整列していなければなりません。";
             break;
         case EXCEPTION_FLT_DENORMAL_OPERAND:
             csExceptionCode += "One of the operands in a floating-point operation is denormal. A denormal value is one that is too small to represent as a standard floating-point value.";
             csExceptionCode += "\r\n";
             csExceptionCode += "浮動小数点演算のオペランドの 1 つが不正規化値です。不正規化値とは、小さすぎて標準の浮動小数点値として表現できない値です。";
             break;
         case EXCEPTION_FLT_DIVIDE_BY_ZERO:
             csExceptionCode += "The thread tried to divide a floating-point value by a floating-point divisor of zero.";
             csExceptionCode += "\r\n";
             csExceptionCode += "スレッドが浮動小数点値を 0 の浮動小数点除数で除算しようとしました。";
             break;
         case EXCEPTION_FLT_INEXACT_RESULT:
             csExceptionCode += "The result of a floating-point operation cannot be represented exactly as a decimal fraction.";
             csExceptionCode += "\r\n";
             csExceptionCode += "浮動小数点演算の結果を 10 進小数で正確に表現できません。";
             break;
         case EXCEPTION_FLT_INVALID_OPERATION:
             csExceptionCode += "This exception represents any floating-point exception not included in this list.";
             csExceptionCode += "\r\n";
             csExceptionCode += "このリストに含まれていない例外が発生しました。";
             break;
         case EXCEPTION_FLT_OVERFLOW:
             csExceptionCode += "The exponent of a floating-point operation is greater than the magnitude allowed by the corresponding type.";
             csExceptionCode += "\r\n";
             csExceptionCode += "浮動小数点演算の指数が大きく、対応する型によって表現できません。";
             break;
         case EXCEPTION_FLT_STACK_CHECK:
             csExceptionCode += "The stack overflowed or underflowed as the result of a floating-point operation.";
             csExceptionCode += "\r\n";
             csExceptionCode += "浮動小数点演算の結果、スタックのオーバーフローまたはアンダーフローが発生しました。";
             break;
         case EXCEPTION_FLT_UNDERFLOW:
             csExceptionCode += "The exponent of a floating-point operation is less than the magnitude allowed by the corresponding type.";
             csExceptionCode += "\r\n";
             csExceptionCode += "浮動小数点演算の指数が小さく、対応する型によって表現できません。";
             break;
         case EXCEPTION_ILLEGAL_INSTRUCTION:
             csExceptionCode += "The thread tried to execute an invalid instruction.";
             break;
         case EXCEPTION_IN_PAGE_ERROR:
             csExceptionCode += "The thread tried to access a page that was not present, and the system was unable to load the page. For example, this exception might occur if a network connection is lost while running a program over the network.";
             break;
         case EXCEPTION_INT_DIVIDE_BY_ZERO:
             csExceptionCode += "The thread tried to divide an integer value by an integer divisor of zero.";
             csExceptionCode += "\r\n";
             csExceptionCode += "スレッドが整数値を 0 の整数除数で除算しようとしました。";
             break;
         case EXCEPTION_INT_OVERFLOW:
             csExceptionCode += "The result of an integer operation caused a carry out of the most significant bit of the result.";
             csExceptionCode += "\r\n";
             csExceptionCode += "整数演算結果の最上位ビットが繰り上がりました。";
             break;
         case EXCEPTION_INVALID_DISPOSITION:
             csExceptionCode += "An exception handler returned an invalid disposition to the exception dispatcher. Programmers using a high-level language such as C should never encounter this exception.";
             break;
         case EXCEPTION_NONCONTINUABLE_EXCEPTION:
             csExceptionCode += "The thread tried to continue execution after a noncontinuable exception occurred.";
             csExceptionCode += "\r\n";
             csExceptionCode += "継続不可能な例外が発生した後、スレッドが実行を継続しようとしました。";
             break;
         case EXCEPTION_PRIV_INSTRUCTION:
             csExceptionCode += "The thread tried to execute an instruction whose operation is not allowed in the current machine mode.";
             csExceptionCode += "\r\n";
             csExceptionCode += "現在のマシンモードで許可されていない演算を行う命令をスレッドが実行しようとしました。";
             break;
         case EXCEPTION_SINGLE_STEP:
             csExceptionCode += "A trace trap or other single-instruction mechanism signaled that one instruction has been executed.";
             csExceptionCode += "\r\n";
             csExceptionCode += "トレーストラップなどの単一命令メカニズムから 1 つの命令の実行が通知されました。";
             break;
         case EXCEPTION_STACK_OVERFLOW:
             csExceptionCode += "The thread used up its stack.";
             break;
         default:
             csExceptionCode += "Unknown.";
             break;
         }
         csExceptionRecordInfo += csExceptionCode;
         csExceptionRecordInfo += "\r\n";

         // その他情報
         CString csExceptionOther;
         csExceptionOther.Format("ExceptionFlags : %d\r\nExceptionRecord : 0x%08x\r\nExceptionAddress : 0x%08x\r\nNumberParameters : %d",
             ExceptionInfo->ExceptionRecord->ExceptionFlags,
             ExceptionInfo->ExceptionRecord->ExceptionRecord,
             ExceptionInfo->ExceptionRecord->ExceptionAddress,
             ExceptionInfo->ExceptionRecord->NumberParameters
    //      ExceptionInfo->ExceptionRecord->ExceptionInformation,
    //        ExceptionInfo->ContextRecord );

         csExceptionRecordInfo += csExceptionOther;

         BTCfj_FLogOutput(CFJ_LIB_BTCNF,CFJ_LVL_NEG,(char*)csExceptionRecordInfo.GetString());
         BTCfj_FLogOutput(CFJ_LIB_BTCNF,CFJ_LVL_NEG,"ExceptionFilter() END");

         return EXCEPTION_CONTINUE_SEARCH;
    }

    関連記事

    ページ上部へ戻る