Namespaces
Variants

std::chrono:: ambiguous_local_time

From cppreference.net
定义于头文件 <chrono>
class ambiguous_local_time ;
(C++20 起)

定义一种异常对象类型,用于报告试图将不明确的 std::chrono::local_time 转换为 std::chrono::sys_time 时未指定 std::chrono::choose (如 choose::earliest choose::latest )的情况。

此异常由 std::chrono::time_zone::to_sys 及调用它的函数(例如接收 std::chrono::local_time 参数的 std::chrono::zoned_time 构造函数)抛出。

cpp/error/exception cpp/error/runtime error std-chrono-ambiguous local time-inheritance.svg

继承关系图

目录

成员函数

(constructor)
构造异常对象
(公开成员函数)
operator=
替换异常对象
(公开成员函数)
what
返回说明性字符串
(公开成员函数)

std::chrono::ambiguous_local_time:: ambiguous_local_time

template < class Duration >

ambiguous_local_time ( const std:: chrono :: local_time < Duration > & tp,

const std:: chrono :: local_info & i ) ;
(1) (since C++20)
ambiguous_local_time ( const ambiguous_local_time & other ) noexcept ;
(2) (since C++20)

构造异常对象。

1) 通过 what ( ) 返回的说明字符串等效于执行以下代码后 os. str ( ) 生成的内容:
std::ostringstream os;
os << tp << " is ambiguous.  It could be\n"
   << tp << ' ' << i.first.abbrev << " == "
   << tp - i.first.offset << " UTC or\n"
   << tp << ' ' << i.second.abbrev  << " == "
   << tp - i.second.offset  << " UTC";
如果 i. result ! = std :: chrono :: local_info :: ambiguous ,则行为未定义。
2) 复制构造函数。如果 * this other 都具有动态类型 std::chrono::ambiguous_local_time ,则 std:: strcmp ( what ( ) , other. what ( ) ) == 0

参数

tp - 尝试转换的时间点
i - 描述转换尝试结果的 std::chrono::local_info
other - 要复制的另一个 ambiguous_local_time 对象

异常

可能抛出 std::bad_alloc

备注

由于不允许在复制派生自 std::exception 的标准库类时抛出异常,此消息通常作为单独分配的引用计数字符串在内部存储。

std::chrono::ambiguous_locale_time:: operator=

ambiguous_locale_time & operator = ( const ambiguous_locale_time & other ) noexcept ;
(since C++20)

使用 other 的内容进行赋值。如果 * this other 都具有动态类型 std::chrono::ambiguous_locale_time ,则赋值后满足 std:: strcmp ( what ( ) , other. what ( ) ) == 0

参数

other - 用于赋值的另一个异常对象

返回值

* this

std::chrono::ambiguous_locale_time:: what

virtual const char * what ( ) const noexcept ;
(since C++20)

返回解释性字符串。

返回值

指向实现定义的以空字符结尾的字符串的指针,该字符串包含解释性信息。该字符串适合转换并显示为 std::wstring 。该指针保证至少在获取它的异常对象被销毁之前,或者在异常对象上调用非const成员函数(例如拷贝赋值运算符)之前保持有效。

备注

实现允许但不要求重写 what()

继承自 std:: exception

成员函数

[virtual]
销毁异常对象
( std::exception 的虚公开成员函数)
[virtual]
返回说明性字符串
( std::exception 的虚公开成员函数)

参见

用于报告本地时间不存在的异常
(类)