Upload
eytan
View
25
Download
2
Embed Size (px)
DESCRIPTION
第十三章. 程式除錯與測試. 本章學習目標:. 介紹 Visual C++ 2005 的偵錯環境 在偵錯之前,針對專案屬性進行偵錯資訊格式設定 如何進行程式碼的偵錯,如何設定中斷點 介紹些常見的錯誤,學習如何避免這些錯誤的發生 利用 _DEBUG 巨集,配合 assert() 函式來避免程式中錯誤的發生 利用 try/catch 敘述來攔截錯誤,如何在函數、類別進行例外處理. 程式為何要進行偵錯?當然是希望應用程式能輸出正確結果!即使是一個簡易的應用程式也必須經過測試和除錯。所以在本章節中,我們為各位詳細介紹 Visual C++ 在程式除錯與測試方面的相關技巧與資訊. - PowerPoint PPT Presentation
Citation preview
Visual C++ 2005_DEBUGassert()try/catchVisual C++
13-1 Visual C++ 2005
13-1 Visual C++ 2005 Bug(debugging)10~15
Visual C++ 2005 Visual C++ 2005F5Visual C++ 2005
13-1 Visual C++ 2005
13-1-1 Visual C++ 2005
SetConfig.cpp(1)
SetConfig.cpp(2)
SetConfig.cppkey34563456
13-1 Visual C++ 2005
13-1-2 3
.
../ErrConfig
4
Visual C++ 2005Visual C++ 2005/Z7/Zi/ZI
5
(/Od
/DEBUG
DEBUGDEBUG*.exeDLLPDBPDB
13-1 Visual C++ 2005
13-1-3
/
SetConfig.cpp
(F11)(F10)
.SetConfig.cpp13-18coutF119ostream
..13-2SetConfig.cppostream
13-38F1010
13-1 Visual C++ 2005
13-1-4 F10main()
.F108 inkeykeyinkeykey3456
..key F10foriforF10123456Enter
13F1014 keyinkeyi1ans13keyinkey0F10151419202124for14if
.14ifans
..ans
19ifans==5false()ans == 0
SetConfig.cpp()
13-1 Visual C++ 2005
13-1-5 SetBreak.vcrpojfor
SetBreak.vcproj5short-32,768 ~ + 32,7676forcount
.F97count7
..F9
count0 1
2
3
4F5count0
5count-32768count < 100
6F599count99Visual C++ 2005
13-2
13-2 C++
13-2
13-2-1 _DEBUG_DEBUG#ifdef/#endifVisual C++Debug#ifdef#endif_DEBUGDebugReleaseErrPoint.vcproj
ErrPoint.vcproj\debug.h_DEBUG_DEBUGAssertion_DEBUG#ifdef _DEBUG #endif
ErrPoint.vcproj\ErrPoint.cpp(1)
ErrPoint.vcproj\ErrPoint.cpp(2)
ErrPoint.cpp3assert412~15POINT_TRACE13
13-2
13-2-2 assertassert ErrPoint.cpp16assert()ptr assert()abort()ptrNULLErrPoint.cpp16assert()ptr
13-3
13-3 Bug
13-3
13-3-1 l10o i
.2sum
.. sum = 5556while
13-3
13-3-2 ErrStatement.vcproj
ErrStatement.vcprojvalue
13-3
13-3-3 newdelete
13-4
13-4 C++Exceptions
13-4
13-4-1 main()trycatch
try...catchtrycatch
simpleTry.cpp(1)
simpleTry.cpp(2)
simpleTry.cpp11~20trycatch010010001315throw18catch
13-4
13-4-2
FuncTry.cpp(1)simpleTry.cpp
FuncTry.cpp(2)
7~1713getNumber()19~29getNumber()
13-4
13-4-3
.. MyClassthrowtry/catch
message.h4~8Messagethrow6~8
ClassTry.vcproj(1)
ClassTry.vcproj(2)
ClassTry.vcproj
ClassTry.vcproj3~11Number8engmathchin13~21handle()16~18if100100throwMessage29~32catchshow()25~28tryNumbersubjecthandle()100100
.Visual C++ 2005
.._DEBUGassertC++Exceptionsthrowtrycatch