Shows how to use xtd::exception_services::exception_dispatch_info class.
#include <xtd/xtd>
auto main() -> int {
auto capture_exception = exception_services::exception_dispatch_info {};
thread::start_new([&] {
try {
throw invalid_operation_exception("Ouch there are an exception !");
} catch (...) {
capture_exception = exception_services::exception_dispatch_info::capture();
}
}).join();
if (capture_exception) {
try {
console::write_line("Rethrow the captured exception :");
capture_exception.rethrow();
} catch (const exception& e) {
console::write_line(e);
}
}
}