システム例外のキャッチ
C++でtry/catchを使ってWin32システムが投げる例外(nullアクセスとか)をキャッチしたいんだけど、
Win32システムエラーを受け取る型が分からないので調べてみた。
#include "stdafx.h" #include <windows.h> #include <assert.h> #include <stdlib.h> #include <conio.h> int filter(PEXCEPTION_POINTERS ExceptionPointers) { PEXCEPTION_RECORD ExceptionRecord = ExceptionPointers->ExceptionRecord; if ((ExceptionRecord->ExceptionFlags & 0x10) == 0) { /* not a nested exception, throw one */ printf("エラーだ!0x%08x\n", ExceptionRecord->ExceptionCode ); } else { printf("ネスト例外だ!\n"); return 1; } //assert(false); return 0; } int _tmain(int argc, _TCHAR* argv[]) { __try { int *nullpo = (int *)0x14445452; printf("error?\n"); int a = *nullpo; printf( "value 0x%08x = %d", nullpo, a ); } __except ( filter(GetExceptionInformation()) ) { printf( "2重にエラーだ!!\n" ); } getch(); return 0; }
これで一応キャッチできるけど、出来ればtry/catchでcatchしたいなぁ。
とりあえず__try/__exceptの上にtry/catchかぶせたら怒られた。
どうすればいいんですか。
ちなみにPEXCEPTION_POINTERS をcatchしようとしたけどcatchできなかったす。