Visual Studio 2008 C ++プログラムがあり、プログラムは__try
/__except
ブロックでラップされてSEH例外をキャプチャします。例外フィルターはエラーログを作成し、ユーザーに欠陥レポートの送信方法に関する詳細な指示を提供します。
__try
フィルタ内のコードを別の/__except
ブロックでラップする必要がありますか?そうでない場合、それを除いてどうなりますか?もしそうなら、それはどのように扱われるべきですか?
static int MyFilter( struct _EXCEPTION_POINTERS* ep )
{
/*
Code to log the exception information, and instruct the user
on how to submit a defect report. Should this be in another
__try/__except block?
*/
return EXCEPTION_EXECUTE_HANDLER;
}
int WINAPI _tWinMain( HINSTANCE hInstance,
HINSTANCE /*hPrevInstance*/,
LPTSTR lpstrCmdLine,
int nCmdShow )
{
int result = 0;
__try
{
result = Execute( hInstance, lpstrCmdLine, nCmdShow );
}
__except( MyFilter( GetExceptionInformation() ) )
{
// empty
}
return 0;
}
ありがとう、PaulH
編集:例外が発生した
場合MyFilter
、私は無限の例外ループに入ります。だから、それは必要__try
/__except
処理をしているように見えます。私はこれを行うことを検討しています:
static int MyFilter( struct _EXCEPTION_POINTERS* ep )
{
__try
{
/*
Code to log the exception information, and instruct the user
on how to submit a defect report.
*/
// cause an exception
int x = 0, y = 1 / x;
}
__except( EXCEPTION_EXECUTE_HANDLER ) { /*empty*/ }
return EXCEPTION_EXECUTE_HANDLER;
}
この場合、プログラムは異常終了し、OSに例外を渡して処理する必要があります。あれは正しいですか?