Skip to content

Commit d0ef04f

Browse files
committed
fix: minor changes in cpp/language/exceptions
1 parent 056165d commit d0ef04f

File tree

5 files changed

+69
-67
lines changed

5 files changed

+69
-67
lines changed

src/content/docs/cpp/language/exceptions.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import { FeatureTestMacro, FeatureTestMacroValue } from "@components/feature-tes
1313

1414
Exception handling provides a way of transferring control and information from some point in the execution of a program to a handler associated with a point previously passed by the execution (in other words, exception handling transfers control up the call stack).
1515

16-
Evaluating a <DocLink dest="cpp/language/throw.html#throw_expressions">`throw` expression</DocLink> will throw an exception. Exceptions can also be thrown in <DocLink dest="cpp/language/throw.html#throw_expressions">other contexts</DocLink>.
16+
Evaluating a <DocLink dest="cpp/language/exceptions/throw.html#throw_expressions">`throw` expression</DocLink> will throw an exception. Exceptions can also be thrown in <DocLink dest="cpp/language/exceptions/throw.html#throw_expressions">other contexts</DocLink>.
1717

18-
In order for an exception to be caught, the `throw` expression has to be inside a <DocLink dest="cpp/language/try">`try` block</DocLink>, and the `try` block has to contain a <DocLink dest="cpp/language/catch">handler</DocLink> that matches the type of the exception object.
18+
In order for an exception to be caught, the `throw` expression has to be inside a <DocLink dest="cpp/language/exceptions/try">`try` block</DocLink>, and the `try` block has to contain a <DocLink dest="cpp/language/exceptions/catch">handler</DocLink> that matches the type of the exception object.
1919

2020
When declaring a function, the following specification(s) may be provided to limit the types of the exceptions a function may throw:
2121

22-
- <Revision since="C++17"><DocLink dest="cpp/language/cpp/language/except_spec">dynamic exception specifications</DocLink></Revision>
23-
- <Revision since="C++11"><DocLink dest="cpp/language/cpp/language/noexcept_spec">noexcept specifications</DocLink></Revision>
22+
- <Revision until="C++17"><DocLink dest="cpp/language/exceptions/except_spec">dynamic exception specifications</DocLink></Revision>
23+
- <Revision since="C++11"><DocLink dest="cpp/language/exceptions/noexcept_spec">noexcept specifications</DocLink></Revision>
2424

2525
Errors that arise during exception handling are handled by <DocLink dest="cpp/error/terminate">`std::terminate`</DocLink> and <Revision since="C++17"><DocLink dest="cpp/error/unexpected">`std::unexpected`</DocLink></Revision>.
2626

src/content/docs/cpp/language/exceptions/catch.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ParamDoc, ParamDocList } from "@components/param-doc";
1212

1313
An <DocLink dest="/cpp/language/exceptions">exception</DocLink> can be handled by a handler.
1414

15-
### Handler
15+
## Handler
1616

1717
<DeclDoc id={1}>
1818
<Decl slot="decl">
@@ -71,7 +71,7 @@ If the parameter is declared to have type “array of `T`” or function type `T
7171

7272
A handler with parameter type `T` can be abbreviated as “a handler of type `T`”.
7373

74-
### Matching exceptions
74+
## Matching exceptions
7575

7676
Each `try` block associates with a number of handlers, these handlers form a handler sequence. When an exception is thrown from a `try` block, the handlers in the sequence are tried in order of appearance to match the exception.
7777

@@ -106,11 +106,11 @@ If no match is found among the handlers for a `try` block, the search for a matc
106106

107107
If no matching handler is found, <DocLink dest="/cpp/error/terminate">std::terminate</DocLink> is invoked; whether or not the stack is <DocLink dest="/cpp/language/exceptions/throwing_exceptions#Stack_unwinding">unwound</DocLink> before this invocation of <DocLink dest="/cpp/error/terminate">std::terminate</DocLink> is implementation-defined.
108108

109-
### Handling exceptions
109+
## Handling exceptions
110110

111111
When an exception is thrown, control is transferred to the nearest handler with a matching type; “nearest” means the handler for which the compound statement or the member initializer list (if present) following the `try` keyword was most recently entered by the thread of control and not yet exited.
112112

113-
#### Initializing the handler parameter
113+
### Initializing the handler parameter
114114

115115
The parameter declared in the parameter list (if any), of type “possibly cv-qualified `T`” or “lvalue reference to possibly cv-qualified `T`”, is initialized from the <DocLink dest="/cpp/language/exceptions/throwing_exceptions#Exception_object">exception object</DocLink>, of type `E`, as follows:
116116

@@ -123,7 +123,7 @@ When the parameter is declared as an object, any changes to that object will not
123123

124124
When the parameter is declared as a reference to an object, any changes to the referenced object are changes to the exception object and will have effect should that object be rethrown.
125125

126-
#### Activating the handler
126+
### Activating the handler
127127

128128
A handler is considered _active_ when initialization is complete for the parameter (if any) of the handler.
129129

@@ -133,7 +133,7 @@ A handler is no longer considered active when the handler exits.
133133

134134
The exception with the most recently activated handler that is still active is called the _currently handled exception_. Such an exception can be <DocLink dest="/cpp/language/exceptions/throwing_exceptions#throw_expressions">rethrown</DocLink>.
135135

136-
### Control flow
136+
## Control flow
137137

138138
The `compound-statement` of a handler is a <DocLink dest="/cpp/language/statements#Control-flow-limited_statements">control-flow-limited statement</DocLink>:
139139

@@ -153,7 +153,7 @@ void f()
153153
}
154154
```
155155

156-
### Notes
156+
## Notes
157157

158158
<DocLink dest="/cpp/language/exceptions/throwing_exceptions#Stack_unwinding">Stack unwinding</DocLink> occurs while control is transferring to a handler. When a handler becomes active, stack unwinding is already completed.
159159

@@ -198,11 +198,11 @@ catch (const float* pf)
198198
}
199199
```
200200

201-
### Keywords
201+
## Keywords
202202

203203
- <DocLink dest="/cpp/keyword/catch">`catch`</DocLink>
204204

205-
### Example
205+
## Example
206206

207207
The following example demonstrates several usage cases of the handlers:
208208

@@ -247,7 +247,7 @@ Accessing the 11th element of the vector...
247247
a standard exception was caught, with message: 'out_of_range'
248248
```
249249

250-
### Defect reports
250+
## Defect reports
251251

252252
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
253253

@@ -302,7 +302,7 @@ The following behavior-changing defect reports were applied retroactively to pre
302302
</DR>
303303
</DRList>
304304

305-
### References
305+
## References
306306

307307
- C++23 standard (ISO/IEC 14882:2024):
308308
- 14.4 Handling an exception [except.handle]
@@ -319,7 +319,7 @@ The following behavior-changing defect reports were applied retroactively to pre
319319
- C++98 standard (ISO/IEC 14882:1998):
320320
- 15.3 Handling an exception [except.handle]
321321

322-
### See also
322+
## See also
323323

324324
- <DocLink dest="/cpp/language/exceptions/try">`try` block</DocLink>
325325
- <DocLink dest="/cpp/language/exceptions/throw">Throwing exceptions</DocLink>

src/content/docs/cpp/language/exceptions/noexcept.mdx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ It can be used within a function template's <DocLink dest="/cpp/language/excepti
2222
noexcept(/*$s:expression*/)
2323
```
2424
</Decl>
25-
</DeclDoc>
2625
27-
Returns a <DocLink dest="/cpp/language/value_category#prvalue">prvalue</DocLink> of type `bool`. The result is `true` if <Revision until="C++17">the set of <DocLink dest="/cpp/language/exceptions/exception_specification/dynamic_specification" text="potential exceptions" /> of the _expression_ is empty</Revision><Revision since="C++17">_expression_ is specified to be <DocLink dest="/cpp/language/exceptions/exception_specification/noexcept_specification" text="non-throwing" /></Revision>, and `false` otherwise.
26+
Returns a <DocLink dest="/cpp/language/value_category#prvalue">prvalue</DocLink> of type `bool`. The result is `true` if <Revision until="C++17">the set of <DocLink dest="/cpp/language/exceptions/exception_specification/dynamic_specification" text="potential exceptions" /> of the _expression_ is empty</Revision><Revision since="C++17">_expression_ is specified to be <DocLink dest="/cpp/language/exceptions/exception_specification/noexcept_specification">non-throwing</DocLink></Revision>, and `false` otherwise.
2827
29-
_expression_ is an <DocLink dest="/cpp/language/expressions#Potentially-evaluated_expressions">unevaluated operand</DocLink>.
28+
_expression_ is an <DocLink dest="/cpp/language/expressions#Potentially-evaluated_expressions">unevaluated operand</DocLink>.
3029
31-
<Revision since="C++17">If _expression_ is a prvalue, <DocLink dest="/cpp/language/implicit_cast#Temporary_materialization">temporary materialization</DocLink> is applied.</Revision>
30+
<Revision since="C++17">If _expression_ is a prvalue, <DocLink dest="/cpp/language/implicit_cast#Temporary_materialization">temporary materialization</DocLink> is applied.</Revision>
31+
</DeclDoc>
3232
3333
## Notes
3434
@@ -40,7 +40,7 @@ If _expression_ is of a class type or (possibly multidimensional) array thereof,
4040
4141
## Keywords
4242
43-
* <DocLink dest="/cpp/keywords/noexcept">`noexcept`</DocLink>
43+
* <DocLink dest="/cpp/keywords/noexcept">`noexcept`</DocLink>
4444
4545
## Example
4646
@@ -119,33 +119,35 @@ V(lvalue V) is noexcept(false)
119119
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
120120

121121
<DRList>
122-
<DR kind="cwg" id={2722} std="C++17">
123-
<Fragment slot="behavior-published">
124-
it was unclear whether temporary materialization is applied if _expression_ is a prvalue
125-
</Fragment>
126-
<Fragment slot="correct-behavior">
127-
it is applied in this case
128-
</Fragment>
129-
</DR>
130-
<DR kind="cwg" id={2792} std="C++11">
131-
<Fragment slot="behavior-published">
132-
the `noexcept` operator was required to determine whether exceptions may be thrown in the case of encountering undefined behavior
133-
</Fragment>
134-
<Fragment slot="correct-behavior">
135-
not required
136-
</Fragment>
137-
</DR>
122+
<DR kind="cwg" id={2722} std="C++17">
123+
<Fragment slot="behavior-published">
124+
it was unclear whether temporary materialization is applied if _expression_ is a prvalue
125+
</Fragment>
126+
<Fragment slot="correct-behavior">
127+
it is applied in this case
128+
</Fragment>
129+
</DR>
130+
<DR kind="cwg" id={2792} std="C++11">
131+
<Fragment slot="behavior-published">
132+
the `noexcept` operator was required to determine whether exceptions may be thrown in the case of encountering undefined behavior
133+
</Fragment>
134+
<Fragment slot="correct-behavior">
135+
not required
136+
</Fragment>
137+
</DR>
138138
</DRList>
139139

140140
## See also
141141

142142
<DescList>
143143
<Desc>
144144
<DocLink slot="item" dest="/cpp/language/exceptions/noexcept_spec">noexcept specifier<Revision since="C++11"/></DocLink>
145-
* specifies whether a function could throw exceptions
145+
146+
specifies whether a function could throw exceptions
146147
</Desc>
147148
<Desc>
148149
<DocLink slot="item" dest="/cpp/language/exceptions/exception_spec">Dynamic exception specification<Revision until="C++17"/></DocLink>
149-
* specifies what exceptions are thrown by a function<Revision traits={[{ trait: "deprecated", since: "C++26" }]}/>
150+
151+
<Revision traits={[{ trait: "deprecated", since: "C++26" }]}>specifies what exceptions are thrown by a function</Revision>
150152
</Desc>
151153
</DescList>

src/content/docs/cpp/language/exceptions/throw.mdx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import { ParamDoc, ParamDocList } from "@components/param-doc";
1212

1313
Throwing an <DocLink dest="cpp/language/exceptions">exception</DocLink> transfers control to a <DocLink dest="cpp/language/catch">handler</DocLink>.
1414

15-
An exception can be thrown from <DocLink dest="cpp/language/throw#throw_expressions">`throw` expressions</DocLink>, the following contexts may also throw exceptions:
15+
An exception can be thrown from <DocLink dest="cpp/language/exceptions/throw#throw_expressions">`throw` expressions</DocLink>, the following contexts may also throw exceptions:
1616

1717
- <DocLink dest="cpp/memory/new/operator_new">allocation functions</DocLink>
1818
- <DocLink dest="cpp/language/dynamic_cast">`dynamic_cast`</DocLink>
1919
- <DocLink dest="cpp/language/typeid">`typeid`</DocLink>
2020
- <DocLink dest="cpp/language/new">`new` expressions</DocLink>
2121
- <DocLink dest="cpp/standard_library">standard library</DocLink> functions
2222

23-
### Exception object
23+
## Exception object
2424

2525
Throwing an exception initializes an object with dynamic <DocLink dest="cpp/language/storage_duration">storage duration</DocLink>, called the *exception object*.
2626

@@ -30,7 +30,7 @@ If the type of the exception object would be one of the following types, the pro
3030
- an <DocLink dest="cpp/language/abstract_class">abstract class type</DocLink>
3131
- a pointer to an incomplete type other than (possibly cv-qualified) `void`
3232

33-
#### Constructing and destructing exception objects
33+
### Constructing and destructing exception objects
3434

3535
Given the type of the exception object as `T`:
3636

@@ -41,7 +41,7 @@ Given the type of the exception object as `T`:
4141

4242
The memory for the exception object is allocated in an unspecified way. The only guarantee is that the storage will never be allocated by global <DocLink dest="cpp/memory/new/operator_new">allocation functions</DocLink>.
4343

44-
If a <DocLink dest="cpp/language/catch">handler</DocLink> exits by <DocLink dest="cpp/language/throw#throw_expressions">rethrowing</DocLink>, control is passed to another handler for the same exception object. The exception object is not destructed in this case.
44+
If a <DocLink dest="cpp/language/catch">handler</DocLink> exits by <DocLink dest="cpp/language/exceptions/throw#throw_expressions">rethrowing</DocLink>, control is passed to another handler for the same exception object. The exception object is not destructed in this case.
4545

4646
<RevisionBlock until="C++11">
4747
When the last remaining active handler for the exception exits by any means other than rethrowing, the exception object is destroyed and the implementation may deallocate the memory for the temporary object in an unspecified way.
@@ -57,7 +57,7 @@ The points of potential destruction for the exception object are:
5757
Among all points of potential destruction for the exception object, there is an unspecified last one where the exception object is destroyed. All other points <DocLink dest="cpp/language/multithread">happen before</DocLink> that last one. The implementation may then deallocate the memory for the exception object in an unspecified way.
5858
</RevisionBlock>
5959

60-
### `throw` expressions
60+
## `throw` expressions
6161

6262
<DeclDoc id = {1}>
6363
<Decl slot="decl">
@@ -104,7 +104,7 @@ catch (...) // catch all exceptions
104104
}
105105
```
106106

107-
### Stack unwinding
107+
## Stack unwinding
108108

109109
Once the exception object is constructed, the control flow works backwards (up the call stack) until it reaches the start of a <DocLink dest="cpp/language/try">`try` block</DocLink>, at which point the parameters of all associated handlers are compared, in order of appearance, with the type of the exception object to find a <DocLink dest="cpp/language/catch#Matching_exceptions">match</DocLink>. If no match is found, the control flow continues to unwind the stack until the next `try` block, and so on. If a match is found, the control flow jumps to the matching handler.
110110

@@ -124,7 +124,7 @@ If any function that is called directly by the stack unwinding mechanism, after
124124

125125
If an exception is thrown and not caught, including exceptions that escape the initial function of <DocLink dest="cpp/thread/thread">`std::thread`</DocLink>, the main function, and the constructor or destructor of any static or thread-local objects, then <DocLink dest="cpp/error/terminate">`std::terminate`</DocLink> is called. It is implementation-defined whether any stack unwinding takes place for uncaught exceptions.
126126

127-
### Notes
127+
## Notes
128128

129129
When rethrowing exceptions, the second form must be used to avoid object slicing in the (typical) case where exception objects use inheritance:
130130

@@ -162,11 +162,11 @@ int main()
162162
}
163163
```
164164
165-
### Keywords
165+
## Keywords
166166
167167
- <DocLink dest="cpp/keyword/throw">`throw`</DocLink>
168168
169-
### Example
169+
## Example
170170
171171
```cpp
172172
#include <iostream>
@@ -242,7 +242,7 @@ C::C() exiting with exception
242242
main() failed to create C with: error
243243
```
244244

245-
### Defect reports
245+
## Defect reports
246246

247247
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
248248

@@ -297,7 +297,7 @@ The following behavior-changing defect reports were applied retroactively to pre
297297
</DR>
298298
</DRList>
299299

300-
### References
300+
## References
301301

302302

303303
- C++23 standard (ISO/IEC 14882:2024):
@@ -318,7 +318,7 @@ The following behavior-changing defect reports were applied retroactively to pre
318318
- C++98 standard (ISO/IEC 14882:1998):
319319
- 15.1 Throwing an exception [except.throw]
320320

321-
### See also
321+
## See also
322322

323323
- <DocLink dest="cpp/language/copy elision">copy elision</DocLink>
324324
- <DocLink dest="cpp/language/try">`try` block</DocLink>

0 commit comments

Comments
 (0)