◐ Shell
clean mode source ↗

std::system_error - cppreference.com

来自cppreference.com

std::system_error 是多种库函数(通常是与 OS 设施交接的函数,例如 std::thread 的构造函数)所抛出的异常类型,该异常与一个相关的 std::error_code 并可能予以报告。

cpp/error/exceptioncpp/error/runtime error

继承图

成员函数

示例

#include <iostream>
#include <system_error>
#include <thread>

int main()
{
    try
    {
        std::thread().detach(); // attempt to detach a non-thread
    }
    catch(const std::system_error& e)
    {
        std::cout << "Caught system_error with code "
                     "[" << e.code() << "] meaning "
                     "[" << e.what() << "]\n";
    }
}

可能的输出:

Caught system_error with code [generic:22] meaning [Invalid argument]