From 5b9931456f595b0a2163fabb65dceac99e0e220f Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Wed, 8 Jan 2025 08:30:18 +0200 Subject: Add backtraces to examples (#5973) * examples: Log stack trace on exceptions For now, this is only implemented on Windows. This helps to address #5520. * examples: Print log file if there is any * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Yong He --- examples/example-main/main.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/example-main/main.cpp (limited to 'examples/example-main') diff --git a/examples/example-main/main.cpp b/examples/example-main/main.cpp new file mode 100644 index 000000000..46ffc7278 --- /dev/null +++ b/examples/example-main/main.cpp @@ -0,0 +1,32 @@ +#include "../stacktrace-windows/common.h" + +#include +#include + +extern int exampleMain(int argc, char** argv); + +#if defined(_WIN32) + +#include + +int main(int argc, char** argv) +{ + __try + { + return exampleMain(argc, argv); + } + __except (exceptionFilter(stdout, GetExceptionInformation())) + { + ::exit(1); + } +} + +#else // defined(_WIN32) + +int main(int argc, char** argv) +{ + // TODO: Catch exception and print stack trace also on non-Windows platforms. + return exampleMain(argc, argv); +} + +#endif -- cgit v1.2.3