命名空间
变体
操作

std::chrono::nonexistent_local_time

来自 cppreference.cn
< cpp‎ | chrono
 
 
日期和时间库
时区
不存在的本地时间 (nonexistent_local_time)
(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
其他 - 另一个 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

参数

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

返回值

*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 的虚公共成员函数) [编辑]

[编辑] 参阅

报告本地时间模糊时抛出的异常
(类) [编辑]