From Jason Turner

[except.pre]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpinsh6qqx/{from.md → to.md} +125 -0
tmp/tmpinsh6qqx/{from.md → to.md} RENAMED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Preamble <a id="except.pre">[[except.pre]]</a>
2
+
3
+ Exception handling provides a way of transferring control and
4
+ information from a point in the execution of a thread to an exception
5
+ handler associated with a point previously passed by the execution. A
6
+ handler will be invoked only by throwing an exception in code executed
7
+ in the handler’s try block or in functions called from the handler’s try
8
+ block.
9
+
10
+ ``` bnf
11
+ try-block:
12
+ 'try' compound-statement handler-seq
13
+ ```
14
+
15
+ ``` bnf
16
+ function-try-block:
17
+ 'try' ctor-initializerₒₚₜ compound-statement handler-seq
18
+ ```
19
+
20
+ ``` bnf
21
+ handler-seq:
22
+ handler handler-seqₒₚₜ
23
+ ```
24
+
25
+ ``` bnf
26
+ handler:
27
+ 'catch' '(' exception-declaration ')' compound-statement
28
+ ```
29
+
30
+ ``` bnf
31
+ exception-declaration:
32
+ attribute-specifier-seqₒₚₜ type-specifier-seq declarator
33
+ attribute-specifier-seqₒₚₜ type-specifier-seq abstract-declaratorₒₚₜ
34
+ '...'
35
+ ```
36
+
37
+ The optional *attribute-specifier-seq* in an *exception-declaration*
38
+ appertains to the parameter of the catch clause [[except.handle]].
39
+
40
+ A *try-block* is a *statement* [[stmt.pre]].
41
+
42
+ [*Note 1*: Within this Clause “try block” is taken to mean both
43
+ *try-block* and *function-try-block*. — *end note*]
44
+
45
+ A `goto` or `switch` statement shall not be used to transfer control
46
+ into a try block or into a handler.
47
+
48
+ [*Example 1*:
49
+
50
+ ``` cpp
51
+ void f() {
52
+ goto l1; // error
53
+ goto l2; // error
54
+ try {
55
+ goto l1; // OK
56
+ goto l2; // error
57
+ l1: ;
58
+ } catch (...) {
59
+ l2: ;
60
+ goto l1; // error
61
+ goto l2; // OK
62
+ }
63
+ }
64
+ ```
65
+
66
+ — *end example*]
67
+
68
+ A `goto`, `break`, `return`, or `continue` statement can be used to
69
+ transfer control out of a try block or handler. When this happens, each
70
+ variable declared in the try block will be destroyed in the context that
71
+ directly contains its declaration.
72
+
73
+ [*Example 2*:
74
+
75
+ ``` cpp
76
+ lab: try {
77
+ T1 t1;
78
+ try {
79
+ T2 t2;
80
+ if (condition)
81
+ goto lab;
82
+ } catch(...) { /* handler 2 */ }
83
+ } catch(...) { /* handler 1 */ }
84
+ ```
85
+
86
+ Here, executing `goto lab;` will destroy first `t2`, then `t1`, assuming
87
+ the *condition* does not declare a variable. Any exception thrown while
88
+ destroying `t2` will result in executing `handler 2`; any exception
89
+ thrown while destroying `t1` will result in executing `handler 1`.
90
+
91
+ — *end example*]
92
+
93
+ A *function-try-block* associates a *handler-seq* with the
94
+ *ctor-initializer*, if present, and the *compound-statement*. An
95
+ exception thrown during the execution of the *compound-statement* or,
96
+ for constructors and destructors, during the initialization or
97
+ destruction, respectively, of the class’s subobjects, transfers control
98
+ to a handler in a *function-try-block* in the same way as an exception
99
+ thrown during the execution of a *try-block* transfers control to other
100
+ handlers.
101
+
102
+ [*Example 3*:
103
+
104
+ ``` cpp
105
+ int f(int);
106
+ class C {
107
+ int i;
108
+ double d;
109
+ public:
110
+ C(int, double);
111
+ };
112
+
113
+ C::C(int ii, double id)
114
+ try : i(f(ii)), d(id) {
115
+ // constructor statements
116
+ } catch (...) {
117
+ // handles exceptions thrown from the ctor-initializer and from the constructor statements
118
+ }
119
+ ```
120
+
121
+ — *end example*]
122
+
123
+ In this Clause, “before” and “after” refer to the “sequenced before”
124
+ relation [[intro.execution]].
125
+