// 异常处理.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "异常处理.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// The one and only application object
/*
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
CString strHello;
strHello.LoadString(IDS_HELLO);
cout << (LPCTSTR)strHello << endl;
}
return nRetCode;
}
*/
#include <iostream>
#include <windows.h>
#include <excpt.h>
using namespace std;
int ExceptionFilter(unsigned int code, struct _EXCEPTION_POINTERS *ep)
{
if ( code == EXCEPTION_ACCESS_VIOLATION )
return EXCEPTION_EXECUTE_HANDLER;
else
return EXCEPTION_CONTINUE_SEARCH;
}
void CppTestFunction()
{
try
{
throw "Test Cpp Exception";
}
catch ( char * )
{
cout << "char * exception caught" << endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int *p = NULL;
__try
{
*p = 1;
}
__except ( ExceptionFilter(GetExceptionCode(), GetExceptionInformation()))
{
cout << "ACCESS VIOLATION CAUGHT" << endl;
}
CppTestFunction();
return 0;
}