skip to content
Ivan's wiki
Site Tools
Search
Tools
Show pagesource
Backlinks
Recent Changes
Media Manager
Sitemap
>
Recent Changes
Media Manager
Sitemap
hpp-exception
This page is read only. You can view the source, but not change it.
# <exception> **[<exception>](https://en.cppreference.com/w/cpp/header/exception)** provides the base class `std::exception` and utilities for exception handling: `std::terminate_handler`, `std::exception_ptr` (capture and rethrow exceptions across threads), and `std::rethrow_exception`. Most user code catches specific exceptions derived from `std::runtime_error` or `std::logic_error`, but this header is essential for implementing exception-safe resource management. This example throws and catches a runtime exception, accessing its descriptive message via the `what()` method. ```cpp // compile: g++ -std=c++11 -o exceptionexample exceptionexample.cpp // run: ./exceptionexample // description: catch and inspect exceptions #include <exception> #include <iostream> #include <stdexcept> int main() { try { throw std::runtime_error("something went wrong"); } catch (const std::exception& e) { std::cout << "caught: " << e.what() << "\n"; } return 0; } ```
Page Tools
Show pagesource
Backlinks
Back to top