Files
2025-10-25 03:02:53 +03:00

55 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[expr.throw]
# 7 Expressions [[expr]](./#expr)
## 7.6 Compound expressions [[expr.compound]](expr.compound#expr.throw)
### 7.6.18 Throwing an exception [expr.throw]
[throw-expression:](#nt:throw-expression "7.6.18Throwing an exception[expr.throw]")
throw [*assignment-expression*](expr.assign#nt:assignment-expression "7.6.19Assignment and compound assignment operators[expr.assign]")opt
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L8025)
A [*throw-expression*](#nt:throw-expression "7.6.18Throwing an exception[expr.throw]") is of type void[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L8028)
A [*throw-expression*](#nt:throw-expression "7.6.18Throwing an exception[expr.throw]") with an operand throws an
exception ([[except.throw]](except.throw "14.2Throwing an exception"))[.](#2.sentence-1)
The array-to-pointer ([[conv.array]](conv.array "7.3.3Array-to-pointer conversion")) and function-to-pointer ([[conv.func]](conv.func "7.3.4Function-to-pointer conversion"))
standard conversions are performed on the operand[.](#2.sentence-2)
The type of the exception object is determined by removing
any top-level [*cv-qualifier*](dcl.decl.general#nt:cv-qualifier "9.3.1General[dcl.decl.general]")*s* from the type of the
(possibly converted) operand[.](#2.sentence-3)
The exception object is copy-initialized ([[dcl.init.general]](dcl.init.general "9.5.1General"))
from the (possibly converted) operand[.](#2.sentence-4)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/expressions.tex#L8039)
A[*throw-expression*](#nt:throw-expression "7.6.18Throwing an exception[expr.throw]") with no operand rethrows the currently handled exception ([[except.handle]](except.handle "14.4Handling an exception"))[.](#3.sentence-1)
If no exception is presently being handled,
the function std::terminate is invoked ([[except.terminate]](except.terminate "14.6.2The std::terminate function"))[.](#3.sentence-2)
Otherwise, the exception is reactivated with the existing exception object;
no new exception object is created[.](#3.sentence-3)
The exception is no longer considered to be caught[.](#3.sentence-4)
[*Example [1](#example-1)*:
An exception handler that cannot completely handle the exception itself
can be written like this:try {// ...} catch (...) { // catch all exceptions// respond (partially) to exceptionthrow; // pass the exception to some other handler}
— *end example*]