C++中没有timeout_exception吗?

pow*_*ete 5 c++ exception std

我正在标准 c++ lib (stdexcept) 中寻找 std::timeout_exception。我还没找到。

好的 - 我可以构建自己的:

class timeout_exception : public std::runtime_error {
public:
  using std::runtime_error::runtime_error;
};
Run Code Online (Sandbox Code Playgroud)

标准库中真的没有超时异常吗?我必须自己定义它吗?

Mar*_*ica 5

不,没有std::timeout_exception。标准不需要定义它,因为标准库中没有任何内容可以抛出它。

明显的候选者是std::timed_lock,但是try_lock_fortry_lock_until只是返回 false。

你的定义看起来不错。