From f2b389e6a7717f84df924060901eb57881224b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 13 Oct 2020 12:23:43 +0300 Subject: [PATCH] test: Change hello-exception.cpp to print to stderr Also flush after each printout, since not all configurations (in particular, wine) flush stderr implicitly. This is often useful when debugging unwinding. --- test/hello-exception.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/hello-exception.cpp b/test/hello-exception.cpp index d883b15..3a4bd49 100644 --- a/test/hello-exception.cpp +++ b/test/hello-exception.cpp @@ -23,10 +23,12 @@ class RecurseClass { public: RecurseClass(int v) : val(v) { - printf("ctor %d\n", val); + fprintf(stderr, "ctor %d\n", val); + fflush(stderr); } ~RecurseClass() { - printf("dtor %d\n", val); + fprintf(stderr, "dtor %d\n", val); + fflush(stderr); } private: int val; @@ -45,19 +47,21 @@ void recurse(int val) { try { recurse(val - 1); } catch (std::exception& e) { - printf("caught exception at %d\n", val); + fprintf(stderr, "caught exception at %d\n", val); + fflush(stderr); } } else { recurse(val - 1); } - printf("finishing function recurse %d\n", val); + fprintf(stderr, "finishing function recurse %d\n", val); + fflush(stderr); } int main(int argc, char* argv[]) { if (argc > 1 && !strcmp(argv[1], "-crash")) { /* This mode is useful for testing backtraces in a debugger. */ crash = true; - printf("Crashing instead of throwing an exception\n"); + fprintf(stderr, "Crashing instead of throwing an exception\n"); } recurse(10); return 0;