[英]How does std::chrono::steady_clock::now report errors?
This is related to my previous question where I asked if std::chrono::steady_clock::now
should be noexcept
. 这与我上一个问题有关 ,我问是否
std::chrono::steady_clock::now
应该是noexcept
。 Now that I know that it should I wonder how does this function report errors? 现在我知道我应该想知道这个函数如何报告错误? For example, a common implementation of this function on Linux uses clock_gettime which can return an error.
例如,Linux上此函数的常见实现使用clock_gettime ,它可以返回错误。
All of the errors that could be reported by the Linux clock_gettime
facility are not possible in a debugged implementation of std::chrono::steady_clock::now()
. Linux
clock_gettime
工具可以报告的所有错误都不可能在std::chrono::steady_clock::now()
的调试实现中实现。
The errors are: 错误是:
int clock_gettime(clockid_t clk_id, struct timespec *tp);
EFAULT
tp points outside the accessible address space.
tp指向可访问的地址空间之外。
There is no user-supplied tp
to get wrong in std::chrono::steady_clock::now()
. 在
std::chrono::steady_clock::now()
没有用户提供的tp
出错。 If std::chrono::steady_clock::now()
passes the wrong tp
to clock_gettime
, it is just a bug in steady_clock
that is easily fixed. 如果
std::chrono::steady_clock::now()
将错误的tp
传递给clock_gettime
,那么它只是一个容易修复的steady_clock
错误。
EINVAL
The clk_id specified is not supported on this system.
此系统不支持指定的clk_id。
There is no user-supplied clk_id
to get wrong in std::chrono::steady_clock::now()
. 在
std::chrono::steady_clock::now()
没有用户提供的clk_id
出错。 If std::chrono::steady_clock::now()
passes the wrong clk_id
to clock_gettime
, it is just a bug in steady_clock
that must be fixed. 如果
std::chrono::steady_clock::now()
将错误的clk_id
传递给clock_gettime
,那么它只是一个必须修复的steady_clock
错误。
Note that an implementation of steady_clock
isn't guaranteed to be portable, and may have to be ported to any given platform and be tested for correctness. 请注意,
steady_clock
的实现不保证是可移植的,并且可能必须移植到任何给定的平台并进行正确性测试。 It might turn out that steady_clock
can not be implemented in terms of clock_gettime
on some platforms. 可能会发现在某些平台上,
clock_gettime
无法实现steady_clock
。
EPERM
clock_settime() does not have permission to set the clock indicated.
clock_settime()无权设置指示的时钟。
Not applicable to steady_clock
as there is no API to set the time. 不适用于
steady_clock
因为没有API来设置时间。
It doesn't. 它没有。 There's no provision in the API for error reporting.
API中没有用于错误报告的规定。 So the Linux implementation must either handle errors internally or not return (eg, via
exit()
or std::terminate()
). 因此Linux实现必须在内部处理错误或不返回(例如,通过
exit()
或std::terminate()
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.