16,472
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <windows.h>
#define VAR_WATCH() printf("nDividend=%d, nDivisor=%d, nResult=%d.\n",\
nDividend, nDivisor, nResult)
int _tmain(int argc, _TCHAR* argv[])
{
int nDividend = 22, nResult = 100;
volatile int nDivisor = 0;
/*nDividend++;
_asm INT 3;
_asm
{
mov eax, eax
__asm _emit 0xcd __asm _emit 0x03
nop
nop
}
DebugBreak();*/
__try
{
printf("Before div in __try block.\n");
VAR_WATCH();
nResult = nDividend / nDivisor;
printf("After div in __try block.\n");
VAR_WATCH();
}
__except(printf("In __except block.\n"), VAR_WATCH(),
GetExceptionCode() == EXCEPTION_INT_DIVIDE_BY_ZERO ?
(nDivisor = 1, printf("Divide zero exception detected.\n"), VAR_WATCH(), EXCEPTION_CONTINUE_EXECUTION) :
(EXCEPTION_CONTINUE_SEARCH))
{
printf("In handler block.\n");
}
return 0;
}
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
#define VAR_WATCH() printf("nDividend=%d, nDivisor=%d, nResult=%d.\n",\
nDividend, nDivisor, nResult)
LONG WINAPI ExceptionHandler(struct _EXCEPTION_POINTERS * pExceptionInfo)
{
pExceptionInfo->ContextRecord->Ecx = 1;
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
int nDividend = 22, nResult = 100;
volatile int nDivisor = 0;
/*nDividend++;
_asm INT 3;
_asm
{
mov eax, eax
__asm _emit 0xcd __asm _emit 0x03
nop
nop
}
DebugBreak();*/
__try
{
printf("Before div in __try block.\n");
VAR_WATCH();
PVOID pHandle = AddVectoredContinueHandler(1,ExceptionHandler);
nResult = nDividend / nDivisor;
printf("After div in __try block.\n");
VAR_WATCH();
RemoveVectoredContinueHandler(pHandle);
}
__except(printf("In __except block.\n"), VAR_WATCH(),
GetExceptionCode() == EXCEPTION_INT_DIVIDE_BY_ZERO ?
(nDivisor = 1, printf("Divide zero exception detected.\n"), VAR_WATCH(), EXCEPTION_CONTINUE_EXECUTION) :
(EXCEPTION_CONTINUE_SEARCH))
{
printf("In handler block.\n");
}
return 0;
}
DWORD ExpFilter(EXCEPTION_POINTERS *pInfo)
{
(*((*pInfo).ContextRecord)).Ecx = 1;
return EXCEPTION_CONTINUE_EXECUTION;
}
void xxxxx::OnBnClickedButton1()
{
int nDividend = 22, nResult = 100;
volatile int nDivisor = 0;
__try
{
printf("Before div in __try block.\n");
// VAR_WATCH();
nResult = nDividend / nDivisor;
printf("After div in __try block.\n");
// VAR_WATCH();
}
__except(nDivisor=1, ExpFilter(GetExceptionInformation()))
{
printf("In handler block.\n");
}
}