Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify how does program terminate due to noexcept #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions book/en-us/09-others.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
2 changes: 1 addition & 1 deletion book/zh-cn/09-others.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void may_throw(); // 可能抛出异常
void no_throw() noexcept; // 不可能抛出异常
```

使用 `noexcept` 修饰过的函数如果抛出异常,编译器会使用 `std::terminate()` 来立即终止程序运行
如果使用 `noexcept` 标记过的函数进行可能抛出异常的操作,编译器会在通过异常退出函数的路径上插入 `std::terminate()` 的调用,以使得程序终止运行

`noexcept` 还能够做操作符,用于操作一个表达式,当表达式无异常时,返回 `true`,否则返回 `false`。

Expand Down