本文介绍了应用程序在生产环境中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我已经在发布模式下构建了一个应用程序,并且没有这样的编译时错误或运行时错误。 我已经编写了自己的单元测试并进行了测试。没有错误。 当我的应用程序进入生产环境并且exe崩溃时。 我该如何处理它?如何检查它在哪个行号中崩溃? 我有创建日志文件,无论何时发生任何事务,登录到日志文件但是exe崩溃什么都没有记录。 i am无法找到?I have build an application in release mode and there no such compile time error or run time error.I have written my own unit test and tested. No Error.when my application went to production envirnoment and exe is crashing.how can i handle it and how can i check where its crashing in which line number?.I have created log file , whenever any transaction is happen , that is logging into the log file but exe is crashing nothing is logging.i am not able to find out?推荐答案//for crash dump analysis//added for CrashDump Analysistypedef BOOL (__stdcall *tMDWD)( IN HANDLE hProcess, IN DWORD ProcessId, IN HANDLE hFile, IN MINIDUMP_TYPE DumpType, IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, OPTIONAL IN CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, OPTIONAL IN CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam OPTIONAL );static tMDWD s_pMDWD;static HMODULE s_hDbgHelpMod;static MINIDUMP_TYPE s_dumpTyp = MiniDumpNormal;static LONG __stdcall MyCrashHandlerExceptionFilter(EXCEPTION_POINTERS* pEx){//#ifdef _M_IX86 if (pEx->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW || ( pEx->ExceptionRecord->ExceptionCode == EXCEPTION_ARRAY_BOUNDS_EXCEEDED) || ( pEx->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) || (pEx->ExceptionRecord->ExceptionCode == EXCEPTION_DATATYPE_MISALIGNMENT) || ( pEx->ExceptionRecord->ExceptionCode == EXCEPTION_FLT_STACK_CHECK) || (pEx->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) || ( pEx->ExceptionRecord->ExceptionCode == EXCEPTION_INT_OVERFLOW) || (pEx->ExceptionRecord->ExceptionCode == EXCEPTION_INVALID_HANDLE) || ( pEx->ExceptionRecord->ExceptionCode == STATUS_UNWIND_CONSOLIDATE )) { // be sure that we have enought space... static char MyStack[1024*128]; // it assumes that DS and SS are the same!!! (this is the case for Win32) // change the stack only if the selectors are the same (this is the case for Win32) //__asm push offset MyStack[1024*128]; //__asm pop esp; __asm mov eax,offset MyStack[1024*128]; __asm mov esp,eax; }//#endif bool bFailed = true; HANDLE hFile; time_t tNow = time( NULL ); struct tm *pTm = localtime( &tNow ); CString strDumpFileName; strDumpFileName.Format(_T("IML_CRASHDUMP_%d%d%d_%02d%02d%02d.dmp"),pTm->tm_mday, pTm->tm_mon, pTm->tm_year, pTm->tm_hour, pTm->tm_min, pTm->tm_sec ); hFile = CreateFile(strDumpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile != INVALID_HANDLE_VALUE) { MINIDUMP_EXCEPTION_INFORMATION stMDEI; stMDEI.ThreadId = GetCurrentThreadId(); stMDEI.ExceptionPointers = pEx; stMDEI.ClientPointers = TRUE; // try to create an miniDump: if (s_pMDWD( GetCurrentProcess(), GetCurrentProcessId(), hFile, s_dumpTyp, &stMDEI, NULL, NULL )) { bFailed = false; // suceeded } CloseHandle(hFile); } if (bFailed) { return EXCEPTION_CONTINUE_SEARCH; } // Optional display an error message FatalAppExit(-1, _T("Application failed!")); // or return one of the following: // - EXCEPTION_CONTINUE_SEARCH // - EXCEPTION_CONTINUE_EXECUTION // - EXCEPTION_EXECUTE_HANDLER return EXCEPTION_CONTINUE_SEARCH; // this will trigger the "normal" OS error-dialog}void InitMiniDumpWriter(){ if (s_hDbgHelpMod != NULL) return; // Initialize the member, so we do not load the dll after the exception has occured // which might be not possible anymore... s_hDbgHelpMod = LoadLibrary(_T("dbghelp.dll")); if (s_hDbgHelpMod != NULL) s_pMDWD = (tMDWD) GetProcAddress(s_hDbgHelpMod, "MiniDumpWriteDump"); // Register Unhandled Exception-Filter: SetUnhandledExceptionFilter(MyCrashHandlerExceptionFilter); //_set_invalid_parameter_handler(MyCrashHandlerExceptionFilter); // Additional call "PreventSetUnhandledExceptionFilter"... // See also: "SetUnhandledExceptionFilter" and VC8 (and later)} 它会在EXE崩溃时产生转储文件(DMP)。 使用VisualStudio IDE打开dmp,你可以找到行号和CPP文件。 问候, RanjithIt will generate a dumpfile(DMP), when it crashes the EXE.Open dmp using VisualStudio IDE there u can find the line number and CPP File.Regards,Ranjith 这篇关于应用程序在生产环境中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-08 12:00