Skip to content

Commit 3629ddd

Browse files
committed
Started Chapter 12
1 parent 7660def commit 3629ddd

File tree

13 files changed

+91
-62
lines changed

13 files changed

+91
-62
lines changed

.vscode/c_cpp_properties.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"windowsSdkVersion": "10.0.22621.0",
1414
"compilerPath": "cl.exe",
1515
"intelliSenseMode": "windows-msvc-x64",
16-
"cppStandard": "gnu++17",
17-
"cStandard": "gnu11"
16+
"cppStandard": "c++17",
17+
"cStandard": "c11"
1818
}
1919
],
2020
"version": 4

Structure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@
813813

814814
简单介绍下异常类及其派生类。
815815

816-
### 实操:`at`成员函数
816+
#### 实操:`at`成员函数
817817

818818
`array`类模板设计一个成员函数`at`,带范围检测,继承自`std::exception`
819819

generalized_part.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ \part*{泛讲篇}
1010
\import{generalized_parts/}{08_a_step_forward_in_classes_and_functions.tex}
1111
\import{generalized_parts/}{09_class_inheritance.tex}
1212
\import{generalized_parts/}{10_common_problems_in_inheritance.tex}
13-
\import{generalized_parts/}{11_templates_and_fundamental_generic_programming.tex}
13+
\import{generalized_parts/}{11_templates_and_fundamental_generic_programming.tex}
14+
\import{generalized_parts/}{12_introduction_to_exceptions.tex}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
\chapter{异常处理简介}
2+
我们在写代码的时候常常会不可避免地犯错误。比如说,一个不小心把 \lstinline@==@ 写成了 \lstinline@=@,像这样:
3+
\begin{lstlisting}
4+
if (n * m = c) { /*...*/ }
5+
\end{lstlisting}
6+
不过所幸,编译器能够一下子发现错误,进而提醒我们这里出错了。\par
7+
但不是所有的bug都可以在编译期发现,比如:
8+
\begin{itemize}
9+
\item 动态内存空间不足,无法分配新的内存空间。
10+
\item 数组访问越界。比如,循环结构 \lstinline@\for(int i=n-1;i>=0;i++)@ 中本来是要写成
11+
\item 为函数/运算符提供了不当的参数。比如,除数为 \lstinline@0@。
12+
\item ……
13+
\end{itemize}
14+
这些问题的发生将导向不可预测的结果,比如程序崩溃。\par
15+
但是编译器可查不出这些问题是否存在,因为它们不是在编译期就能够知道的信息。所以我们需要有一套机制,来对这些运行过程中可能产生的\textbf{异常(Exception)}进行捕获和处理。这也就是本章的核心内容。\par
16+
关于异常处理的知识,说多不多,说少也不少。限于篇幅,在泛讲篇中我们就介绍一下最基础的部分。至于更深入的内容,让我们留到精讲篇吧。\par
17+
\import{../generalized_parts/12_introduction_to_exceptions/}{01_try_catch_throw.tex}
18+
\import{../generalized_parts/12_introduction_to_exceptions/}{02_std_exception.tex}
19+
\import{../generalized_parts/12_introduction_to_exceptions/}{03_noexcept.tex}

generalized_parts/12_introduction_to_exceptions/01_try_catch_throw.tex

Whitespace-only changes.

generalized_parts/12_introduction_to_exceptions/02_std_exception.tex

Whitespace-only changes.

generalized_parts/12_introduction_to_exceptions/03_noexcept.tex

Whitespace-only changes.

main.aux

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,22 @@
229229
\@writefile{toc}{\contentsline {section}{\numberline {11.6}实操:智能指针}{328}{section.11.6}\protected@file@percent }
230230
\@writefile{lol}{\contentsline {lstlisting}{\numberline {11.8}\texttt {unique\_ptr.hpp}}{335}{lstlisting.11.8}\protected@file@percent }
231231
\@writefile{lol}{\contentsline {lstlisting}{\numberline {11.9}\texttt {Definition.tpp}}{337}{lstlisting.11.9}\protected@file@percent }
232+
\@writefile{toc}{\contentsline {chapter}{\numberline {第十二章\hspace {.3em}}异常处理简介}{341}{chapter.12}\protected@file@percent }
233+
\@writefile{lof}{\addvspace {10.0pt}}
234+
\@writefile{lot}{\addvspace {10.0pt}}
232235
\gdef \LT@i {\LT@entry
233236
{1}{42.00002pt}\LT@entry
234237
{1}{136.19997pt}\LT@entry
235238
{1}{117.00002pt}\LT@entry
236239
{1}{52.00002pt}\LT@entry
237240
{1}{86.48302pt}}
238-
\@writefile{toc}{\contentsline {part}{精讲篇}{343}{part*.236}\protected@file@percent }
239-
\@writefile{toc}{\contentsline {chapter}{\numberline {附录 A\hspace {.3em}}C++运算符基本属性}{343}{appendix.A}\protected@file@percent }
241+
\@writefile{toc}{\contentsline {part}{精讲篇}{345}{part*.236}\protected@file@percent }
242+
\@writefile{toc}{\contentsline {chapter}{\numberline {附录 A\hspace {.3em}}C++运算符基本属性}{345}{appendix.A}\protected@file@percent }
240243
\@writefile{lof}{\addvspace {10.0pt}}
241244
\@writefile{lot}{\addvspace {10.0pt}}
242-
\newlabel{ch:appendix_A}{{A}{343}{C++运算符基本属性}{appendix.A}{}}
243-
\@writefile{lot}{\contentsline {table}{\numberline {A.1}{截至C++17的所有运算符}}{343}{table.A.1}\protected@file@percent }
244-
\newlabel{tab:A-1}{{A.1}{343}{截至C++17的所有运算符}{table.A.1}{}}
245+
\newlabel{ch:appendix_A}{{A}{345}{C++运算符基本属性}{appendix.A}{}}
246+
\@writefile{lot}{\contentsline {table}{\numberline {A.1}{截至C++17的所有运算符}}{345}{table.A.1}\protected@file@percent }
247+
\newlabel{tab:A-1}{{A.1}{345}{截至C++17的所有运算符}{table.A.1}{}}
245248
\gdef \LT@ii {\LT@entry
246249
{1}{33.67001pt}\LT@entry
247250
{1}{33.81001pt}\LT@entry
@@ -253,11 +256,11 @@
253256
{1}{26.72002pt}\LT@entry
254257
{1}{27.283pt}\LT@entry
255258
{1}{86.44002pt}}
256-
\@writefile{toc}{\contentsline {chapter}{\numberline {附录 B\hspace {.3em}}ASCII码表(0到127)}{345}{appendix.B}\protected@file@percent }
259+
\@writefile{toc}{\contentsline {chapter}{\numberline {附录 B\hspace {.3em}}ASCII码表(0到127)}{347}{appendix.B}\protected@file@percent }
257260
\@writefile{lof}{\addvspace {10.0pt}}
258261
\@writefile{lot}{\addvspace {10.0pt}}
259-
\@writefile{lot}{\contentsline {table}{\numberline {B.1}{33个ASCII控制字符}}{345}{table.B.1}\protected@file@percent }
260-
\newlabel{tab:B-1}{{B.1}{345}{33个ASCII控制字符}{table.B.1}{}}
262+
\@writefile{lot}{\contentsline {table}{\numberline {B.1}{33个ASCII控制字符}}{347}{table.B.1}\protected@file@percent }
263+
\newlabel{tab:B-1}{{B.1}{347}{33个ASCII控制字符}{table.B.1}{}}
261264
\gdef \LT@iii {\LT@entry
262265
{1}{33.67001pt}\LT@entry
263266
{1}{33.81001pt}\LT@entry
@@ -271,20 +274,20 @@
271274
{1}{33.67001pt}\LT@entry
272275
{1}{33.81001pt}\LT@entry
273276
{1}{26.72002pt}}
274-
\@writefile{lot}{\contentsline {table}{\numberline {B.2}{95个ASCII可打印字符}}{346}{table.B.2}\protected@file@percent }
275-
\newlabel{tab:B-2}{{B.2}{346}{95个ASCII可打印字符}{table.B.2}{}}
276-
\@writefile{toc}{\contentsline {chapter}{\numberline {附录 C\hspace {.3em}}相关数学知识}{347}{appendix.C}\protected@file@percent }
277+
\@writefile{lot}{\contentsline {table}{\numberline {B.2}{95个ASCII可打印字符}}{348}{table.B.2}\protected@file@percent }
278+
\newlabel{tab:B-2}{{B.2}{348}{95个ASCII可打印字符}{table.B.2}{}}
279+
\@writefile{toc}{\contentsline {chapter}{\numberline {附录 C\hspace {.3em}}相关数学知识}{349}{appendix.C}\protected@file@percent }
277280
\@writefile{lof}{\addvspace {10.0pt}}
278281
\@writefile{lot}{\addvspace {10.0pt}}
279-
\@writefile{toc}{\contentsline {section}{\numberline {C.1}数制转换}{347}{section.C.1}\protected@file@percent }
280-
\@writefile{lof}{\contentsline {figure}{\numberline {C.1}{\ignorespaces 一个简单的数字时钟}}{347}{figure.C.1}\protected@file@percent }
281-
\@writefile{lof}{\contentsline {figure}{\numberline {C.2}{\ignorespaces 从计数到乘方}}{348}{figure.C.2}\protected@file@percent }
282-
\@writefile{lof}{\contentsline {figure}{\numberline {C.3}{\ignorespaces 一个12进制乘法表}}{349}{figure.C.3}\protected@file@percent }
283-
\@writefile{lof}{\contentsline {figure}{\numberline {C.4}{\ignorespaces $(1a.c3)_{16}$的形式化表示}}{351}{figure.C.4}\protected@file@percent }
284-
\@writefile{lof}{\contentsline {figure}{\numberline {C.5}{\ignorespaces 通过短除法把十进制数转换成$R$进制}}{354}{figure.C.5}\protected@file@percent }
285-
\@writefile{lof}{\contentsline {figure}{\numberline {C.6}{\ignorespaces 二进制与八进制的转换}}{355}{figure.C.6}\protected@file@percent }
286-
\@writefile{lof}{\contentsline {figure}{\numberline {C.7}{\ignorespaces 二进制与十六进制的转换}}{356}{figure.C.7}\protected@file@percent }
287-
\@writefile{toc}{\contentsline {section}{\numberline {C.2}布尔代数基础}{356}{section.C.2}\protected@file@percent }
288-
\@writefile{lof}{\contentsline {figure}{\numberline {C.8}{\ignorespaces 玛雅数字与阿拉伯数字的对应关系}}{357}{figure.C.8}\protected@file@percent }
289-
\@writefile{toc}{\contentsline {chapter}{跋}{359}{appendix*.245}\protected@file@percent }
290-
\gdef \@abspage@last{368}
282+
\@writefile{toc}{\contentsline {section}{\numberline {C.1}数制转换}{349}{section.C.1}\protected@file@percent }
283+
\@writefile{lof}{\contentsline {figure}{\numberline {C.1}{\ignorespaces 一个简单的数字时钟}}{349}{figure.C.1}\protected@file@percent }
284+
\@writefile{lof}{\contentsline {figure}{\numberline {C.2}{\ignorespaces 从计数到乘方}}{350}{figure.C.2}\protected@file@percent }
285+
\@writefile{lof}{\contentsline {figure}{\numberline {C.3}{\ignorespaces 一个12进制乘法表}}{351}{figure.C.3}\protected@file@percent }
286+
\@writefile{lof}{\contentsline {figure}{\numberline {C.4}{\ignorespaces $(1a.c3)_{16}$的形式化表示}}{353}{figure.C.4}\protected@file@percent }
287+
\@writefile{lof}{\contentsline {figure}{\numberline {C.5}{\ignorespaces 通过短除法把十进制数转换成$R$进制}}{356}{figure.C.5}\protected@file@percent }
288+
\@writefile{lof}{\contentsline {figure}{\numberline {C.6}{\ignorespaces 二进制与八进制的转换}}{357}{figure.C.6}\protected@file@percent }
289+
\@writefile{lof}{\contentsline {figure}{\numberline {C.7}{\ignorespaces 二进制与十六进制的转换}}{358}{figure.C.7}\protected@file@percent }
290+
\@writefile{toc}{\contentsline {section}{\numberline {C.2}布尔代数基础}{358}{section.C.2}\protected@file@percent }
291+
\@writefile{lof}{\contentsline {figure}{\numberline {C.8}{\ignorespaces 玛雅数字与阿拉伯数字的对应关系}}{359}{figure.C.8}\protected@file@percent }
292+
\@writefile{toc}{\contentsline {chapter}{跋}{361}{appendix*.245}\protected@file@percent }
293+
\gdef \@abspage@last{370}

main.log

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex 2023.12.3) 29 JAN 2024 21:08
1+
This is XeTeX, Version 3.141592653-2.6-0.999995 (TeX Live 2023) (preloaded format=xelatex 2023.12.3) 30 JAN 2024 19:10
22
entering extended mode
33
\write18 enabled.
44
file:line:error style messages enabled.
@@ -1862,9 +1862,13 @@ Overfull \hbox (2.07718pt too wide) in paragraph at lines 13--14
18621862
[337]
18631863
Underfull \vbox (badness 10000) has occurred while \output is active []
18641864

1865-
[338])))) (././intensive_part.tex [339] [340
1865+
[338]))) (./generalized_parts/12_introduction_to_exceptions.tex [339] [340
18661866

1867-
] [341] [342]) (./other_parts/appendix.tex (./other_parts/appendices/A.tex
1867+
]
1868+
第十二章
1869+
(./generalized_parts/../generalized_parts/12_introduction_to_exceptions/01_try_catch_throw.tex) (./generalized_parts/../generalized_parts/12_introduction_to_exceptions/02_std_exception.tex) (./generalized_parts/../generalized_parts/12_introduction_to_exceptions/03_noexcept.tex))) (././intensive_part.tex [341] [342
1870+
1871+
] [343] [344]) (./other_parts/appendix.tex (./other_parts/appendices/A.tex
18681872
附录 A
18691873

18701874
Underfull \hbox (badness 6063) in paragraph at lines 16--16
@@ -1876,41 +1880,41 @@ Underfull \hbox (badness 7468) in paragraph at lines 46--46
18761880
[][][]\TU/SimSun(0)/m/n/8.33344 注 意,| 重 载 运 算 符 对 参 数 有 特 殊 要 求:| 必 须 接 收 至 少 一 个 自 定 义 类 型 的 参 数,| 可 以 是 类 或 枚 举 类。| 比 如 说,|
18771881
[]
18781882

1879-
[343
1883+
[345
18801884

1881-
]) (./other_parts/appendices/B.tex [344]
1885+
]) (./other_parts/appendices/B.tex [346]
18821886
附录 B
1883-
[345
1887+
[347
18841888

1885-
]) (./other_parts/appendices/C.tex [346]
1889+
]) (./other_parts/appendices/C.tex [348]
18861890
附录 C
18871891
File: appendices/../images/other_parts/C_digital_clock.png Graphic file (type bmp)
18881892
<appendices/../images/other_parts/C_digital_clock.png>
1889-
[347
1893+
[349
18901894

18911895
]
18921896
File: appendices/../images/other_parts/C_from_counting_to_exponentiation.png Graphic file (type bmp)
18931897
<appendices/../images/other_parts/C_from_counting_to_exponentiation.png>
18941898
File: appendices/../images/other_parts/C_duodecimal_multiplication_table.png Graphic file (type bmp)
18951899
<appendices/../images/other_parts/C_duodecimal_multiplication_table.png>
1896-
[348]
1900+
[350]
18971901
Underfull \vbox (badness 2753) has occurred while \output is active []
18981902

1899-
[349] [350]
1903+
[351] [352]
19001904
File: appendices/../images/other_parts/C_formatted_representation_of_a_number.png Graphic file (type bmp)
19011905
<appendices/../images/other_parts/C_formatted_representation_of_a_number.png>
1902-
[351] [352]
1906+
[353] [354]
19031907
File: appendices/../images/other_parts/C_short_division.png Graphic file (type bmp)
19041908
<appendices/../images/other_parts/C_short_division.png>
1905-
[353] [354]
1909+
[355] [356]
19061910
File: appendices/../images/other_parts/C_bin_to_oct.png Graphic file (type bmp)
19071911
<appendices/../images/other_parts/C_bin_to_oct.png>
1908-
[355]
1912+
[357]
19091913
File: appendices/../images/other_parts/C_bin_to_hex.png Graphic file (type bmp)
19101914
<appendices/../images/other_parts/C_bin_to_hex.png>
19111915
File: appendices/../images/other_parts/C_maya_numbers.png Graphic file (type bmp)
19121916
<appendices/../images/other_parts/C_maya_numbers.png>
1913-
[356])) (./other_parts/afterword.tex [357] [358
1917+
[358])) (./other_parts/afterword.tex [359] [360
19141918

19151919
])
19161920
File: images/other_parts/back_cover.pdf Graphic file (type pdf)
@@ -1921,28 +1925,28 @@ File: images/other_parts/back_cover.pdf Graphic file (type pdf)
19211925
<use images/other_parts/back_cover.pdf, page 1>
19221926
File: images/other_parts/back_cover.pdf Graphic file (type pdf)
19231927
<use images/other_parts/back_cover.pdf, page 1>
1924-
[359]
1928+
[361]
19251929
File: images/other_parts/back_cover.pdf Graphic file (type pdf)
19261930
<use images/other_parts/back_cover.pdf, page 1>
19271931
File: images/other_parts/back_cover.pdf Graphic file (type pdf)
19281932
<use images/other_parts/back_cover.pdf, page 1>
19291933
File: images/other_parts/back_cover.pdf Graphic file (type pdf)
19301934
<use images/other_parts/back_cover.pdf, page 1>
1931-
[360] (./main.aux)
1935+
[362] (./main.aux)
19321936
***********
19331937
LaTeX2e <2023-11-01>
19341938
L3 programming layer <2022/08/05>
19351939
***********
19361940
Package rerunfilecheck Info: File `main.out' has not changed.
1937-
(rerunfilecheck) Checksum: 57A0CAC6D409FB5A3D513C8D608A6107;8331.
1941+
(rerunfilecheck) Checksum: 6D801363F088B981411683256DD5FA64;8431.
19381942
)
19391943
Here is how much of TeX's memory you used:
1940-
27802 strings out of 474924
1941-
720073 string characters out of 5765037
1944+
27832 strings out of 474924
1945+
722362 string characters out of 5765037
19421946
2050189 words of memory out of 5000000
1943-
48736 multiletter control sequences out of 15000+600000
1947+
48751 multiletter control sequences out of 15000+600000
19441948
571829 words of font info for 166 fonts, out of 8000000 for 9000
19451949
1348 hyphenation exceptions out of 8191
19461950
93i,18n,111p,1239b,1918s stack positions out of 10000i,1000n,20000p,200000b,200000s
19471951

1948-
Output written on main.pdf (368 pages).
1952+
Output written on main.pdf (370 pages).

main.out

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@
7070
\BOOKMARK [1][-]{section.11.4}{\376\377\174\173\152\041\147\177\166\204\123\313\121\103\060\001\133\236\117\213\123\026\116\016\162\171\123\026}{chapter.11}% 70
7171
\BOOKMARK [1][-]{section.11.5}{\376\377\000S\000T\000L\173\200\116\313}{chapter.11}% 71
7272
\BOOKMARK [1][-]{section.11.6}{\376\377\133\236\144\315\377\032\146\172\200\375\143\007\224\210}{chapter.11}% 72
73-
\BOOKMARK [-1][-]{part*.236}{\376\377\174\276\213\262\173\307}{}% 73
74-
\BOOKMARK [0][-]{appendix.A}{\376\377\000C\000+\000+\217\320\173\227\173\046\127\372\147\054\134\136\140\047}{part*.236}% 74
75-
\BOOKMARK [0][-]{appendix.B}{\376\377\000A\000S\000C\000I\000I\170\001\210\150\377\010\0000\122\060\0001\0002\0007\377\011}{part*.236}% 75
76-
\BOOKMARK [0][-]{appendix.C}{\376\377\166\370\121\163\145\160\133\146\167\345\213\306}{part*.236}% 76
77-
\BOOKMARK [1][-]{section.C.1}{\376\377\145\160\122\066\217\154\143\142}{appendix.C}% 77
78-
\BOOKMARK [1][-]{section.C.2}{\376\377\136\003\134\024\116\343\145\160\127\372\170\100}{appendix.C}% 78
79-
\BOOKMARK [0][-]{appendix*.245}{\376\377\215\313}{part*.236}% 79
73+
\BOOKMARK [0][-]{chapter.12}{\376\377\137\002\136\070\131\004\164\006\173\200\116\313}{part*.3}% 73
74+
\BOOKMARK [-1][-]{part*.236}{\376\377\174\276\213\262\173\307}{}% 74
75+
\BOOKMARK [0][-]{appendix.A}{\376\377\000C\000+\000+\217\320\173\227\173\046\127\372\147\054\134\136\140\047}{part*.236}% 75
76+
\BOOKMARK [0][-]{appendix.B}{\376\377\000A\000S\000C\000I\000I\170\001\210\150\377\010\0000\122\060\0001\0002\0007\377\011}{part*.236}% 76
77+
\BOOKMARK [0][-]{appendix.C}{\376\377\166\370\121\163\145\160\133\146\167\345\213\306}{part*.236}% 77
78+
\BOOKMARK [1][-]{section.C.1}{\376\377\145\160\122\066\217\154\143\142}{appendix.C}% 78
79+
\BOOKMARK [1][-]{section.C.2}{\376\377\136\003\134\024\116\343\145\160\127\372\170\100}{appendix.C}% 79
80+
\BOOKMARK [0][-]{appendix*.245}{\376\377\215\313}{part*.236}% 80

0 commit comments

Comments
 (0)