diff --git a/README.md b/README.md index 6871fde..f5d1e1e 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,10 @@ Cpptrace also has a C API, docs [here](docs/c-api.md). - [Raw Traces](#raw-traces) - [Utilities](#utilities) - [Configuration](#configuration) - - [Traced Exceptions](#traced-exceptions) + - [Traces From All Exceptions](#traces-from-all-exceptions) + - [How it works](#how-it-works) + - [Performance](#performance) + - [Traced Exception Objects](#traced-exception-objects) - [Wrapping std::exceptions](#wrapping-stdexceptions) - [Exception handling with cpptrace](#exception-handling-with-cpptrace) - [Signal-Safe Tracing](#signal-safe-tracing) @@ -80,7 +83,30 @@ const auto raw_trace = cpptrace::generate_raw_trace(); raw_trace.resolve().print(); ``` -Cpptrace also provides exception types that store stack traces: +Cpptrace provides a way to produce stack traces on arbitrary exceptions. More information on this system +[below](#traces-from-all-exceptions). +```cpp +#include +void foo() { + throw std::runtime_error("foo failed"); +} +int main() { + CPPTRACE_TRY { + foo(); + } CPPTRACE_CATCH(const std::exception& e) { + std::cerr<<"Exception: "< @@ -89,7 +115,7 @@ void trace() { } ``` -![Inlining](res/exception.png) +![Exception](res/exception.png) Additional notable features: @@ -342,11 +368,70 @@ namespace cpptrace { } ``` -### Traced Exceptions +### Traces From All Exceptions -Cpptrace provides an interface for a traced exceptions, `cpptrace::exception`, as well as a set of exception classes -that that generate stack traces when thrown. These exceptions generate relatively lightweight raw traces and resolve -symbols and line numbers lazily if and when requested. +Cpptrace provides `CPPTRACE_TRY` and `CPPTRACE_CATCH` macros that allow a stack trace to be collected from the current +thrown exception object, with no overhead in the non-throwing path: + +```cpp +CPPTRACE_TRY { + foo(); +} CPPTRACE_CATCH(const std::exception& e) { + std::cout<<"Exception: "< [!NOTE] +> This section is largely obsolete now that cpptrace provides a better mechanism for collecting +> [traces from exceptions](#traces-from-exceptions) + Cpptrace exceptions can provide great information for user-controlled exceptions. For non-cpptrace::exceptions that may originate outside of code you control, e.g. the standard library, cpptrace provides some wrapper utilities that can rethrow these exceptions nested in traced cpptrace exceptions. The trace won't be perfect, the trace will start where @@ -446,6 +535,10 @@ std::cout< [!NOTE] +> This section pertains to cpptrace traced exception objects and not the mechanism for collecting +> [traces from arbitrary exceptions](#traces-from-exceptions) + Working with cpptrace exceptions in your code: ```cpp try { @@ -1000,3 +1093,5 @@ This library is under the MIT license. Cpptrace uses libdwarf on linux, macos, and mingw/cygwin unless configured to use something else. If this library is statically linked with libdwarf then the library's binary will itself be LGPL. + +[P2490R3]: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2490r3.html diff --git a/res/from_current.png b/res/from_current.png new file mode 100644 index 0000000..395e3af Binary files /dev/null and b/res/from_current.png differ