From 4b355707c825477413508b82965bc447e8b30d1c Mon Sep 17 00:00:00 2001 From: wfjm Date: Sat, 27 Oct 2018 12:41:12 +0200 Subject: [PATCH] add Rtools::Catch2Cerr --- tools/src/librtools/Rtools.cpp | 28 +++++++++++++++++++++++++--- tools/src/librtools/Rtools.hpp | 8 ++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/tools/src/librtools/Rtools.cpp b/tools/src/librtools/Rtools.cpp index 68739e6a..49388461 100644 --- a/tools/src/librtools/Rtools.cpp +++ b/tools/src/librtools/Rtools.cpp @@ -1,6 +1,6 @@ -// $Id: Rtools.cpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: Rtools.cpp 1059 2018-10-27 10:34:16Z mueller $ // -// Copyright 2011-2017 by Walter F.J. Mueller +// Copyright 2011-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -13,7 +13,8 @@ // // Revision History: // Date Rev Version Comment -// 2017-02-18 852 1.0.7 remove TimeOfDayAsDouble() +// 2018-10-26 1059 1.0.8 add Catch2Cerr() +// 2017-02-18 852 1.0.7 remove TimeOfDayAsDouble() // 2014-11-23 606 1.0.6 add TimeOfDayAsDouble() // 2014-11-08 602 1.0.5 add (int) cast in snprintf to match %d type // 2014-08-22 584 1.0.4 use nullptr @@ -171,5 +172,26 @@ bool CreateBackupFile(const RparseUrl& purl, RerrMsg& emsg) return true; } +//------------------------------------------+----------------------------------- +//! FIXME_docs + +void Catch2Cerr(const char* msg, std::function func) +{ + try { + func(); + } catch (Rexception& e) { + cerr << "Catch2Cerr-E: exception '" << e.ErrMsg().Text() + << "' thrown in " << e.ErrMsg().Meth() + << " caught and dropped in " << msg << endl; + } catch (exception& e) { + cerr << "Catch2Cerr-E: exception '" << e.what() + << " caught and dropped in " << msg << endl; + } catch(...) { + cerr << "Catch2Cerr-E: non std::exception" + << " caught and dropped in " << msg << endl; + } + return; +} + } // end namespace Rtools } // end namespace Retro diff --git a/tools/src/librtools/Rtools.hpp b/tools/src/librtools/Rtools.hpp index a3e0af69..21b95384 100644 --- a/tools/src/librtools/Rtools.hpp +++ b/tools/src/librtools/Rtools.hpp @@ -1,6 +1,6 @@ -// $Id: Rtools.hpp 983 2018-01-02 20:35:59Z mueller $ +// $Id: Rtools.hpp 1059 2018-10-27 10:34:16Z mueller $ // -// Copyright 2011-2017 by Walter F.J. Mueller +// Copyright 2011-2018 by Walter F.J. Mueller // // This program is free software; you may redistribute and/or modify it under // the terms of the GNU General Public License as published by the Free @@ -13,6 +13,7 @@ // // Revision History: // Date Rev Version Comment +// 2018-10-26 1059 1.0.7 add Catch2Cerr() // 2017-02-18 852 1.0.6 remove TimeOfDayAsDouble() // 2017-02-11 850 1.0.5 add Word2Bytes() and Bytes2Word() // 2014-11-23 606 1.0.4 add TimeOfDayAsDouble() @@ -32,6 +33,7 @@ #include #include +#include #include "RerrMsg.hpp" #include "RparseUrl.hpp" @@ -59,6 +61,8 @@ namespace Retro { void Word2Bytes(uint16_t word, uint16_t& byte0, uint16_t& byte1); uint16_t Bytes2Word(uint16_t byte0, uint16_t byte1); + void Catch2Cerr(const char* msg, std::function func); + } // end namespace Rtools } // end namespace Retro