Files
stacktrace/modules/samples/usage_sample_from_exception.cpp
Fedor Osetrov e93f50def8 feat boost.stacktrace: support import std (#231)
Support build with `import std;`. Add Github CI pipeline


---------

Co-authored-by: Fedor Osetrov <fdr400@Fedors-MacBook-Pro.local>
2026-05-11 12:09:09 +03:00

36 lines
733 B
C++

// Copyright Antony Polukhin, 2025-2026.
// Copyright Fedor Osetrov, 2025-2026.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <iostream>
#include <map>
#include <boost/config.hpp>
#include <boost/stacktrace.hpp>
namespace {
BOOST_NOINLINE void foo() {
std::map<int, int> m;
std::ignore = m.at(1);
}
BOOST_NOINLINE void bar() {
foo();
}
}
int main() {
try {
bar();
} catch (const std::exception& ex) {
const auto trace = boost::stacktrace::stacktrace::from_current_exception();
std::cerr << "Exception: " << ex.what() << ", trace:\n" << trace << '\n';
}
}