亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch20.htm

?? good book for learning c++ standard language
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
<!-- This document was created from RTF source by rtftohtml version 3.0.1 -->

	<META NAME="GENERATOR" Content="Symantec Visual Page 1.0">
	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
	<TITLE>Teach Yourself C++ in 21 Days</TITLE>
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF">

<H1 ALIGN="CENTER"><A HREF="ch19.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/htm/ch19.htm"><IMG SRC="../buttons/BLANPREV.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANPREV.GIF"
WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A><A HREF="javascript:if(confirm('http://www.mcp.com/sams  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.mcp.com/sams'" tppabs="http://www.mcp.com/sams"><IMG
SRC="../buttons/BLANHOME.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANHOME.GIF" WIDTH="37" HEIGHT="37" ALIGN="BOTTOM"
BORDER="0"></A><A HREF="../index.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/index.htm"><IMG SRC="../buttons/BLANTOC.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANTOC.GIF"
WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A><A HREF="ch21.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/htm/ch21.htm"><IMG SRC="../buttons/BLANNEXT.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANNEXT.GIF"
WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A></H1>
<H1></H1>

<UL>
	<LI><A HREF="#Heading1">Day 20</A>
	<UL>
		<LI><A HREF="#Heading2">Exceptions and Error Handling</A>
		<UL>
			<LI><A HREF="#Heading3">Bugs, Errors, Mistakes, and Code Rot</A>
			<UL>
				<LI><A HREF="#Heading4">Exceptions</A>
				<LI><A HREF="#Heading5">A Word About Code Rot</A>
			</UL>
			<LI><A HREF="#Heading6">Exceptions</A>
			<UL>
				<LI><A HREF="#Heading7">How Exceptions Are Used</A>
			</UL>
			<LI><A HREF="#Heading8">Listing 20.1. Raising an exception.</A>
			<LI><A HREF="#Heading9">try Blocks</A>
			<LI><A HREF="#Heading10">catch Blocks</A>
			<LI><A HREF="#Heading11">Using try Blocks and catch Blocks</A>
			<UL>
				<LI><A HREF="#Heading12">Catching Exceptions</A>
				<LI><A HREF="#Heading13">More Than One catch Specification</A>
			</UL>
			<LI><A HREF="#Heading14">Listing 20.2. Multiple exceptions.</A>
			<UL>
				<LI><A HREF="#Heading15">Exception Hierarchies</A>
			</UL>
			<LI><A HREF="#Heading16">Listing 20.3. Class hierarchies and exceptions</A><A HREF="#Heading17">.</A>
			<LI><A HREF="#Heading18">Data in Exceptions and Naming Exception Objects</A>
			<LI><A HREF="#Heading19">Listing 20.4. Getting data out of an exception object</A><A
			HREF="#Heading20">.</A>
			<LI><A HREF="#Heading21">Listing 20.5.</A>
			<LI><A HREF="#Heading22">Passing by reference and using virtual functions in exceptions.</A>
			<LI><A HREF="#Heading23">Exceptions and Templates</A>
			<LI><A HREF="#Heading24">Listing 20.6. Using exceptions with templates.</A>
			<LI><A HREF="#Heading25">Exceptions Without Errors</A>
			<LI><A HREF="#Heading26">Bugs and Debugging</A>
			<UL>
				<LI><A HREF="#Heading27">Breakpoints</A>
				<LI><A HREF="#Heading28">Watch Points</A>
				<LI><A HREF="#Heading29">Examining Memory</A>
				<LI><A HREF="#Heading30">Assembler</A>
			</UL>
			<LI><A HREF="#Heading31">Summary</A>
			<LI><A HREF="#Heading32">Q&amp;A</A>
			<LI><A HREF="#Heading33">Workshop</A>
			<UL>
				<LI><A HREF="#Heading34">Quiz</A>
				<LI><A HREF="#Heading35">Exercises</A>
			</UL>
		</UL>
	</UL>
</UL>

<P>
<HR SIZE="4">

<H2 ALIGN="CENTER"><A NAME="Heading1"></A><FONT COLOR="#000077">Day 20</FONT></H2>

<H2 ALIGN="CENTER"><A NAME="Heading2"></A><FONT COLOR="#000077">Exceptions and Error
Handling</FONT></H2>
<P>The code you've seen in this book has been created for illustration purposes.
It has not dealt with errors so that you would not be distracted from the central
issues being presented. Real-world programs must take error conditions into consideration.</P>
<P>Today you will learn

<UL>
	<LI>What exceptions are.
	<P>
	<LI>How exceptions are used, and what issues they raise.
	<P>
	<LI>How to build exception hierarchies.
	<P>
	<LI>How exceptions fit into an overall error-handling approach.
	<P>
	<LI>What a debugger is.
</UL>

<H3 ALIGN="CENTER"><A NAME="Heading3"></A><FONT COLOR="#000077">Bugs, Errors, Mistakes,
and Code Rot</FONT></H3>
<P>All programs have bugs. The bigger the program, the more bugs, and many of those
bugs actually &quot;get out the door&quot; and into final, released software. That
this is true does not make it okay, and making robust, bug-free programs is the number-one
priority of anyone serious about programming.</P>
<P>The single biggest problem in the software industry is buggy, unstable code. The
biggest expense in many major programming efforts is testing and fixing. The person
who solves the problem of producing good, solid, bulletproof programs at low cost
and on time will revolutionize the software industry.</P>
<P>There are a number of discrete kinds of bugs that can trouble a program. The first
is poor logic: The program does just what you asked, but you haven't thought through
the algorithms properly. The second is syntactic: You used the wrong idiom, function,
or structure. These two are the most common, and they are the ones most programmers
are on the lookout for.</P>
<P>Research and real-world experience have shown beyond a doubt that the later in
the development process you find a problem, the more it costs to fix it. The least
expensive problems or bugs to fix are the ones you manage to avoid creating. The
next cheapest are those the compiler spots. The C++ standards force compilers to
put a lot of energy into making more and more bugs show up at compile time.</P>
<P>Bugs that get compiled in but are caught at the first test--those that crash every
time--are less expensive to find and fix than those that are flaky and only crash
once in a while.</P>
<P>A bigger problem than logic or syntactic bugs is unnecessary fragility: Your program
works just fine if the user enters a number when you ask for one, but it crashes
if the user enters letters. Other programs crash if they run out of memory, or if
the floppy disk is left out of the drive, or if the modem drops the line.</P>
<P>To combat this kind of fragility, programmers strive to make their programs bulletproof.
A bulletproof program is one that can handle anything that comes up at runtime, from
bizarre user input to running out of memory.</P>
<P>It is important to distinguish between bugs, which arise because the programmer
made a mistake in syntax; logic errors, which arise because the programmer misunderstood
the problem or how to solve it; and exceptions, which arise because of unusual but
predictable problems such as running out of resources (memory or disk space).
<H4 ALIGN="CENTER"><A NAME="Heading4"></A><FONT COLOR="#000077">Exceptions</FONT></H4>
<P>Programmers use powerful compilers and sprinkle their code with <TT>assert</TT>s,
as discussed on Day 17, &quot;The Preprocessor,&quot; to catch programming errors.
They use design reviews and exhaustive testing to find logic errors.</P>
<P>Exceptions are different, however. You can't eliminate exceptional circumstances;
you can only prepare for them. Your users will run out of memory from time to time,
and the only question is what you will do. Your choices are limited to these:

<UL>
	<LI>Crash the program.
	<P>
	<LI>Inform the user and exit gracefully.
	<P>
	<LI>Inform the user and allow the user to try to recover and continue.
	<P>
	<LI>Take corrective action and continue without disturbing the user.
</UL>

<P>While it is not necessary or even desirable for every program you write to automatically
and silently recover from all exceptional circumstances, it is clear that you must
do better than crashing.</P>
<P>C++ exception handling provides a type-safe, integrated method for coping with
the predictable but unusual conditions that arise while running a program.
<H4 ALIGN="CENTER"><A NAME="Heading5"></A><FONT COLOR="#000077">A Word About Code
Rot</FONT></H4>
<P>Code rot is a well-proven phenomenon. Code rot is when code deteriorates due to
being neglected. Perfectly well-written, fully debugged code will develop new and
bizarre behavior six months after you release it, and there isn't much you can do
to stop it. What you can do, of course, is write your programs so that when you go
back to fix the spoilage, you can quickly and easily identify where the problems
are.


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Code rot is somewhat of a programmer's
	joke used to explain how bug-free code suddenly becomes unreliable. It does, however,
	teach an important lesson. Programs are enormously complex, and bugs, errors, and
	mistakes can hide for a long time before turning up. Protect yourself by writing
	easy-to-maintain code. 
<HR>


</BLOCKQUOTE>

<P>This means that your code must be commented even if you don't expect anyone else
to ever look at it. Six months after you deliver your code, you will read it with
the eyes of a total stranger, bewildered by how anyone could ever have written such
convoluted and twisty code and expected anything but disaster.
<H3 ALIGN="CENTER"><A NAME="Heading6"></A><FONT COLOR="#000077">Exceptions</FONT></H3>
<P>In C++, an exception is an object that is passed from the area of code where a
problem occurs to the part of the code that is going to handle the problem. The type
of the exception determines which area of code will handle the problem, and the contents
of the object thrown, if any, may be used to provide feedback to the user.</P>
<P>The basic idea behind exceptions is fairly straightforward:

<UL>
	<LI>The actual allocation of resources (for example, the allocation of memory or
	the locking of a file) is usually done at a very low level in the program.
	<P>
	<LI>The logic of what to do when an operation fails, memory cannot be allocated,
	or a file cannot be locked is usually high in the program, with the code for interacting
	with the user.
	<P>
	<LI>Exceptions provide an express path from the code that allocates resources to
	the code that can handle the error condition. If there are intervening layers of
	functions, they are given an opportunity to clean up memory allocations, but are
	not required to include code whose only purpose is to pass along the error condition.
</UL>

<H4 ALIGN="CENTER"><A NAME="Heading7"></A><FONT COLOR="#000077">How Exceptions Are
Used</FONT></H4>
<P><TT>try</TT> blocks are created to surround areas of code that may have a problem.
For example:</P>
<PRE><FONT COLOR="#0066FF">try
{
SomeDangerousFunction();
}
</FONT></PRE>
<P><TT>catch</TT> blocks handle the exceptions thrown in the <TT>try</TT> block.
For example:</P>
<PRE><FONT COLOR="#0066FF">try
{
SomeDangerousFunction();
}
catch(OutOfMemory)
{
// take some actions
}
catch(FileNotFound)
{
// take other action
}
</FONT></PRE>
<P>The basic steps in using exceptions are

<DL>
	<DD><B>1.</B> Identify those areas of the program in which you begin an operation
	that might raise an exception, and put them in <TT>try</TT> blocks.<BR>
	<BR>
	<B>2.</B> Create <TT>catch</TT> blocks to catch the exceptions if they are thrown,
	to clean up allocated memory, and to inform the user as appropriate. Listing 20.1
	illustrates the use of both <TT>try</TT> blocks and <TT>catch</TT> blocks.<BR>
	<B><BR>
	</B>
<HR>
<FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B><I>Exceptions </I>are objects
	used to transmit information about a problem. 
<HR>

	<P>
<HR>
<FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>try block </I>is a block
	surrounded by braces in which an exception may be thrown. 
<HR>
</P>
	<P>
<HR>
<FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>catch block</I> is the
	block immediately following a <TT>try</TT> block, in which exceptions are handled.</P>
	<P>When an exception is thrown (or raised), control transfers to the <TT>catch</TT>
	block immediately following the current <TT>try</TT> block. 
<HR>

</DL>



<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Some older compilers do not support
	exceptions. Exceptions are, however, part of the emerging C++ standard. All major
	compiler vendors have committed to supporting exceptions in their next releases,
	if they have not already done so. If you have an older compiler, you won't be able
	to compile and run the exercises in this chapter. It's still a good idea to read
	through the entire chapter, however, and return to this material when you upgrade
	your compiler. 
<HR>


</BLOCKQUOTE>

<P><A NAME="Heading8"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 20.1. Raising
an exception.</B></FONT>
<PRE><FONT COLOR="#0066FF">0:       #include &lt;iostream.h&gt;
1:    
2:       const int DefaultSize = 10;
3:    
4:       class Array
5:       {
6:       public:
7:          // constructors
8:          Array(int itsSize = DefaultSize);
9:          Array(const Array &amp;rhs);
10:          ~Array() { delete [] pType;}
11:    
12:          // operators
13:          Array&amp; operator=(const Array&amp;);
14:          int&amp; operator[](int offSet);
15:          const int&amp; operator[](int offSet) const;
16:    
17:          // accessors
18:          int GetitsSize() const { return itsSize; }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲黄一区二区三区| 国产日韩欧美高清| 亚洲精品一区二区三区四区高清| 国产亚洲欧美日韩俺去了| 中文字幕一区二区三区视频| 日日夜夜精品免费视频| 国产成人免费视频| 久久国产精品区| 亚洲va天堂va国产va久| 国产精品久久毛片av大全日韩| 午夜久久电影网| 丁香六月综合激情| 日韩精品综合一本久道在线视频| 亚洲女人****多毛耸耸8| 九九精品一区二区| 欧美日韩国产电影| 亚洲蜜臀av乱码久久精品蜜桃| 国内精品国产成人国产三级粉色| 欧美日韩国产色站一区二区三区| 国产精品久久久久久久久免费樱桃| 麻豆成人久久精品二区三区红| 欧洲色大大久久| 亚洲婷婷国产精品电影人久久| 国产福利一区二区三区视频 | 亚洲激情校园春色| 成人看片黄a免费看在线| 26uuu精品一区二区在线观看| 日韩成人精品视频| 欧美男生操女生| 午夜精品福利一区二区蜜股av| 在线视频观看一区| 亚洲人成亚洲人成在线观看图片| 成人免费视频caoporn| 久久品道一品道久久精品| 国产在线播放一区三区四| 宅男噜噜噜66一区二区66| 五月婷婷久久丁香| 欧美一区二区美女| 精品一区二区在线观看| 精品女同一区二区| 色婷婷久久99综合精品jk白丝| 综合婷婷亚洲小说| 色综合天天做天天爱| 亚洲一区二区三区视频在线播放 | 国产精品自拍三区| 国产亚洲成年网址在线观看| 成人午夜av在线| 日韩一区欧美一区| 91久久一区二区| 天天综合色天天综合色h| 欧美精品一卡二卡| 国产一区三区三区| 中文字幕日韩精品一区| 欧美系列一区二区| 美日韩一区二区| 国产色产综合产在线视频 | 精品一区二区综合| 欧美激情综合网| 在线观看精品一区| 美女一区二区视频| 国产精品免费看片| 欧美四级电影在线观看| 黄页网站大全一区二区| 国产精品入口麻豆九色| 欧美色中文字幕| 久久av中文字幕片| 亚洲欧美一区二区在线观看| 欧美无砖专区一中文字| 久久99精品国产麻豆婷婷| 国产精品久久久久影院色老大| 91伊人久久大香线蕉| 免费在线欧美视频| 1区2区3区国产精品| 91精品国产高清一区二区三区| 国产精品亚洲第一区在线暖暖韩国 | 亚洲成人在线免费| 日韩黄色片在线观看| 国产免费成人在线视频| 91精品国产欧美日韩| 99精品视频在线观看| 日韩电影在线一区二区| 成人欧美一区二区三区| 精品国产一区二区在线观看| 色8久久人人97超碰香蕉987| 久久国产福利国产秒拍| 亚洲精品乱码久久久久久日本蜜臀| 欧美成人r级一区二区三区| 91婷婷韩国欧美一区二区| 国内不卡的二区三区中文字幕| 亚洲午夜久久久久久久久久久| 久久综合九色综合欧美就去吻| 欧美性大战xxxxx久久久| 成人免费毛片嘿嘿连载视频| 日韩av一区二区三区| 亚洲美女视频在线观看| 中文字幕av一区二区三区免费看| 欧美区一区二区三区| 色综合天天综合给合国产| 国产成人精品午夜视频免费| 日韩高清中文字幕一区| 亚洲影视在线播放| 亚洲精品乱码久久久久久久久| 久久久av毛片精品| 精品国内片67194| 欧美一卡2卡三卡4卡5免费| 91蝌蚪porny| 成人免费高清在线| 粉嫩av一区二区三区在线播放 | 亚洲777理论| 一区二区三区国产精华| 亚洲欧美自拍偷拍| 中文字幕第一区| 中日韩av电影| 国产精品福利影院| 国产精品久久久久久久久久免费看| 欧美精品一区视频| 久久婷婷色综合| 国产午夜亚洲精品羞羞网站| 久久久精品国产免大香伊| 久久视频一区二区| 国产欧美日韩激情| 国产精品欧美久久久久无广告| 国产女人水真多18毛片18精品视频| 国产偷国产偷亚洲高清人白洁| 精品国产一区二区在线观看| 久久九九99视频| 国产日韩欧美在线一区| 欧美激情一区二区| 亚洲男女毛片无遮挡| 亚洲综合精品自拍| 午夜精品免费在线| 久久超碰97人人做人人爱| 激情图区综合网| 成人免费视频一区二区| 色综合久久久久久久久久久| 欧美午夜不卡视频| 日韩免费看网站| 中文字幕不卡一区| 亚洲一区二区精品视频| 日本强好片久久久久久aaa| 国产一区美女在线| 91在线播放网址| 欧美日韩亚洲综合在线| 精品久久久久久亚洲综合网| 国产精品免费久久| 偷拍亚洲欧洲综合| 国产一区二区三区久久悠悠色av| 成人毛片在线观看| 欧美精品粉嫩高潮一区二区| 亚洲精品一区二区三区在线观看| 中文字幕一区二区三区不卡在线| 亚洲一区av在线| 国产一二精品视频| 欧美伊人久久久久久久久影院| 日韩免费福利电影在线观看| 国产精品第四页| 奇米色一区二区三区四区| 成人激情免费视频| 91精品国产综合久久香蕉麻豆| 欧美激情中文字幕一区二区| 午夜在线成人av| 成人开心网精品视频| 91精品国产麻豆| 亚洲精品videosex极品| 韩日欧美一区二区三区| 欧洲一区二区三区在线| 国产日产亚洲精品系列| 性久久久久久久久久久久| 成人美女视频在线看| 日韩美女视频一区二区在线观看| 亚洲三级久久久| 国产毛片精品一区| 在线综合+亚洲+欧美中文字幕| 中文字幕一区二区三区四区不卡 | 丁香五精品蜜臀久久久久99网站| 欧洲一区二区三区在线| 国产精品久久久久久久久图文区| 麻豆精品精品国产自在97香蕉| 欧美在线观看视频一区二区三区| 国产午夜一区二区三区| 久久不见久久见中文字幕免费| 欧美综合在线视频| 日韩美女视频一区二区| 国产福利一区二区| 精品av综合导航| 日本在线不卡视频| 欧美日本在线播放| 一区二区三区欧美在线观看| 成人午夜在线免费| 精品国产乱码久久久久久闺蜜| 天天色综合天天| 欧美日韩情趣电影| 亚洲高清视频中文字幕| 91丨九色丨黑人外教| 国产精品国产三级国产普通话三级| 精品一区二区三区在线观看国产 | 欧洲一区二区三区免费视频| 亚洲色欲色欲www在线观看| 成人h动漫精品一区二区| 欧美高清在线一区|