在VS2005中将工程的属性设置成为可以捕获SHE异常是不是在debug时候就能捕捉所有的异常阿。
急 急 急急!!!
急 急 急急!!!
解决方案 »
- 请问SendMessage发送WM_CLOSE消息的最后两个参数wParam,lParam具体的0,1分别代表什么意思
- 磁盘过滤问题,谢谢回答!!!
- VC雕虫小技集(二)
- 删除记录后怎么立即更新?
- 位图背景上画方框再擦除
- 100分求excel插件的界面开发的思路
- 求候捷的《MFC深入浅出》
- 在线求救?怎样用VC实现统计的TC源程序中所定义的函数,并列举出来
- 谁比较了解联想软件(武汉)设计中心的情况
- win2000和win9x有关数据库的函数有哪些是通用的,哪些是不兼容的。为什么我做的程序有98下运行良好,在2000下却报错?
- xml问题
- 做一个基于对话框的串口通信的工程,希望能够当按下一个按钮,能够在对话框中显示实时曲线
SEH是Windows系统提供的功能,跟开发工具无关。值得一提的是,VC将SEH进行了封装 try catch finally,c++中也可以用c的封装 __try{}__except(){} 和 __try{}__finally{}. 所以当你建立一个C++ try块时,编译器就生成一个SEH__try块。一个C++catch测试变成一个SEH异常过滤器,并且catch中的代码变成SEH__except块中的代码。实际上,当你写一条C++ throw语句时,编译器就生成一个对Windows的RaiseException函数的调用。用于throw语句的变量传递给RaiseException作为附加的参数。catch(...)能捕获所有的异常(应该是绝大部分),但要放到所有catch段的最后,但不能获取详细的信息.
要是想了解更多,看看<windows核心编程>,里面有章就是讲这个
#include <dbghelp.h>
#include <tchar.h>
#include <afx.h>
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT#include <iostream>#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif///////////////////////////////////////////////////////////////////////////////
// Directives
//#pragma comment ( lib, "dbghelp.lib")///////////////////////////////////////////////////////////////////////////////
// Test data and code
//// Contents of the user data streams
char Message1[] = "This is the first data stream...";
char Message2[] = "and this is the second data stream"; // Stream identifiers
// (LastReservedStream constant is defined in MINIDUMP_STREAM_TYPE
// enumeration in DbgHelp.h; all user data stream identifiers
// must be larger than LastReservedStream)
const ULONG32 cFirstStreamID = LastReservedStream + 1; //Last stream reserved for use by Windows Operating Systems. const ULONG32 cSecondStreamID = LastReservedStream + 2;
///////////////////////////////////////////////////////////////////////////////
// Minidump creation function
//
void CreateMiniDump( EXCEPTION_POINTERS* pep, LPCTSTR lpszOupputDir)
{
// Open the file
TCHAR szFilePath[MAX_PATH * 2 +1] = {0}, szFileNam[32] = {0};
SYSTEMTIME tCurTime;
GetSystemTime(&tCurTime);
_stprintf(szFileNam, _T("MiniDump%04d%02d%02d%02d%02d%02d.dmp"), tCurTime.wYear, tCurTime.wMonth, tCurTime.wDay,
tCurTime.wHour, tCurTime.wMinute, tCurTime.wSecond);
_tmakepath(szFilePath, NULL, lpszOupputDir, szFileNam, NULL);
HANDLE hFile = CreateFile( szFilePath, GENERIC_READ | GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if( ( hFile != NULL ) && ( hFile != INVALID_HANDLE_VALUE ) )
{
// Create the minidump // Exception information MINIDUMP_EXCEPTION_INFORMATION mdei; mdei.ThreadId = GetCurrentThreadId();
mdei.ExceptionPointers = pep;
mdei.ClientPointers = FALSE; // Minidump type MINIDUMP_TYPE mdt = MiniDumpNormal; // User data streams MINIDUMP_USER_STREAM UserStreams[2]; UserStreams[0].Type = cFirstStreamID;
UserStreams[0].Buffer = Message1;
UserStreams[0].BufferSize = sizeof(Message1); UserStreams[1].Type = cSecondStreamID;
UserStreams[1].Buffer = Message2;
UserStreams[1].BufferSize = sizeof(Message2); MINIDUMP_USER_STREAM_INFORMATION musi; musi.UserStreamCount = 2;
musi.UserStreamArray = UserStreams; // Call MiniDumpWriteDump BOOL rv = MiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(),
hFile, mdt, (pep != 0) ? &mdei : 0, &musi, 0 ); if( !rv )
{
} CloseHandle( hFile );
}
else
{
}}/////////////////////////////////////////////////////////////////////////////
#define INSTALL_SEHCONVERT() ExceptionConvert ecExceptionConvertclass ExceptionConvert
{
public:
ExceptionConvert(){OldFanc = _set_se_translator(trans_func); }
~ExceptionConvert(){_set_se_translator(OldFanc); }
private:
static void trans_func( unsigned int u, EXCEPTION_POINTERS* pExp )
{
throw pExp;
}
_se_translator_function OldFanc;
};
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
INSTALL_SEHCONVERT(); 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.
try
{
cout << _T("begin") << endl;
/*vector<int> aaa;
aaa[1] = 0;*/
TCHAR *szTemp = NULL;
strcpy(szTemp, _T("1111111111111111111111111111111111111111"));
}
catch(EXCEPTION_POINTERS *pex)
{
CreateMiniDump(pex, _T("c:\\"));
}
catch(...)
{
}
} return nRetCode;
}