From 9aaff5f777cff4828c3e8dd1324d5a2620973d86 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Mon, 26 Aug 2024 01:25:06 +0800 Subject: [PATCH] Clarify how does program terminate due to `noexcept` --- book/en-us/09-others.md | 6 +++--- book/zh-cn/09-others.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/book/en-us/09-others.md b/book/en-us/09-others.md index 773a9612..a3021475 100644 --- a/book/en-us/09-others.md +++ b/book/en-us/09-others.md @@ -39,9 +39,9 @@ void may_throw(); // May throw any exception void no_throw() noexcept; // Cannot throw any exception ``` -If a function modified with `noexcept` is thrown, -the compiler will use `std::terminate()` to -immediately terminate the program. +If a function marked `noexcept` performs an operation that possibly throws an exception, +the compiler will insert a `std::terminate()` call to the path exiting the function via an exception, +in order to make the program terminate. `noexcept` can also be used as an operator to manipulate an expression. When the expression has no exception, it returns `true`, diff --git a/book/zh-cn/09-others.md b/book/zh-cn/09-others.md index 8dc1861e..6defc61b 100644 --- a/book/zh-cn/09-others.md +++ b/book/zh-cn/09-others.md @@ -36,7 +36,7 @@ void may_throw(); // 可能抛出异常 void no_throw() noexcept; // 不可能抛出异常 ``` -使用 `noexcept` 修饰过的函数如果抛出异常,编译器会使用 `std::terminate()` 来立即终止程序运行。 +如果使用 `noexcept` 标记过的函数进行可能抛出异常的操作,编译器会在通过异常退出函数的路径上插入 `std::terminate()` 的调用,以使得程序终止运行。 `noexcept` 还能够做操作符,用于操作一个表达式,当表达式无异常时,返回 `true`,否则返回 `false`。