命名空间
变体
操作

std::chrono::nonexistent_local_time

来自 cppreference.cn
< cpp‎ | chrono
 
 
日期和时间库
时间点
(C++11)
(C++20)
时长
(C++11)
时钟
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
一天中的时间
(C++20)(C++20)
(C++20)(C++20)
(C++20)
日历
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)
chrono I/O
(C++20)

时区
(C++20)
(C++20)
(C++20)
(C++20)
nonexistent_local_time
(C++20)
(C++20)
(C++20)
(C++20)
C 风格的日期和时间
 
定义于头文件 <chrono>
class nonexistent_local_time;
(自 C++20 起)

定义了一种对象类型,该对象作为异常抛出,以报告尝试将不存在的 std::chrono::local_time 转换为 std::chrono::sys_time,而没有指定 std::chrono::choose (例如 choose::earliestchoose::latest)。

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

cpp/error/exceptioncpp/error/runtime errorstd-chrono-nonexistent local time-inheritance.svg

继承关系图

内容

[编辑] 成员函数

(构造函数)
构造异常对象
(公有成员函数)
operator=
替换异常对象
(公有成员函数)
what
返回解释性字符串
(公有成员函数)

std::chrono::nonexistent_local_time::nonexistent_local_time

template< class Duration >

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

                        const std::chrono::local_info& i );
(1) (自 C++20 起)
nonexistent_local_time( const nonexistent_local_time& other ) noexcept;
(2) (自 C++20 起)

构造异常对象。

1) what() 返回的解释性字符串等效于以下代码后 os.str() 生成的字符串
std::ostringstream os;
os << tp << " is in a gap between\n"
   << std::chrono::local_seconds(i.first.end.time_since_epoch()) + i.first.offset
   << ' ' << i.first.abbrev << " and\n"
   << std::chrono::local_seconds(i.second.begin.time_since_epoch()) + i.second.offset
   << ' ' << i.second.abbrev
   << " which are both equivalent to\n"
   << i.first.end << " UTC";
如果 i.result != std::chrono::local_info::nonexistent,则行为未定义。
2) 复制构造函数。如果 *thisother 都具有动态类型 std::chrono::nonexistent_local_time,则 std::strcmp(what(), other.what()) == 0

参数

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

异常

可能抛出 std::bad_alloc

注释

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

std::chrono::nonexistent_locale_time::operator=

nonexistent_locale_time& operator=( const nonexistent_locale_time& other ) noexcept;
(自 C++20 起)

将内容赋值为 other 的内容。如果 *thisother 都具有动态类型 std::chrono::nonexistent_locale_time,则赋值后 std::strcmp(what(), other.what()) == 0

参数

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

返回值

*this

std::chrono::nonexistent_locale_time::what

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

返回解释性字符串。

返回值

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

返回的字符串在使用常量求值期间使用普通文字编码进行编码。

(自 C++26 起)

注释

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

继承自 std::runtime_error


继承自 std::exception

成员函数

[虚函数]
销毁异常对象
(std::exception 的虚函数公有成员函数) [编辑]
[虚函数]
返回解释性字符串
(std::exception 的虚函数公有成员函数) [编辑]

[编辑] 参见

抛出异常以报告本地时间不明确
(类) [编辑]