还有,特别是VC程序员为了使开发的系统有更好的可靠性,往往在应用程序的入口函数中(如MFC框架的开发环境下 CXXXApp::InitInstance())和工作线程的入口函数中加上一个顶层的trycatch块,并且使用catch(…)来捕获一切所有的 异常,如下:
BOOL CXXXApp::InitInstance() { if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; }
AfxEnableControlContainer();
// Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need.
#ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif
// 注意这里有一个顶层的trycatch块,并且使用catch(…)来捕获一切所有的异常 try { CXXXDlg dlg; m_pMainWnd = &dlg; int nResponse = dlg.DoModal(); if (nResponse == IDOK) { // TODO: Place code here to handle when the dialog is // dismissed with OK } else if (nResponse == IDCANCEL) { // TODO: Place code here to handle when the dialog is // dismissed with Cancel } } catch(…) { // dump出系统的一些重要信息,并通知管理员查找出现意外异常的原因。 // 同时想办法恢复系统,例如说重新启动应用程序等 }
// Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-81712-4.html
当年台湾经济起飞靠的是越战机遇
可靠性下降维修成本上升是正常现象