skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-system-error
This page is read only. You can view the source, but not change it.
# <system_error> **[<system_error>](https://en.cppreference.com/w/cpp/header/system_error)** provides `std::error_code` and `std::error_category` for OS-level error reporting. Use it to portably capture and classify system errors (like `errno` or Windows HRESULT) without hardcoding values. Most code doesn't use this directly; it's used internally by file operations and network APIs. This example captures an error when opening a nonexistent file and describes it using the generic error category. ```cpp // compile: g++ -std=c++11 -o systemerrorexample systemerrorexample.cpp // run: ./systemerrorexample // description: system error handling #include <system_error> #include <fstream> #include <iostream> int main() { std::ifstream file("nonexistent.txt"); if (!file) { std::error_code ec(errno, std::generic_category()); std::cout << "error: " << ec.message() << "\n"; } return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top