From 6ed829ab3b6233acfb1a7b5ec3412cf5a56ef8f2 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 13 Jun 2019 11:56:46 +0200 Subject: add TOOLS_WARN_EXCEPTION,etc macros to be used for nicer logging of exceptions, along with upcoming clang plugin Change-Id: I028c31ec329652e4842136528605b4cceaae946d Reviewed-on: https://gerrit.libreoffice.org/73949 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/tools/diagnose_ex.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/include/tools/diagnose_ex.h b/include/tools/diagnose_ex.h index 596e44c4694d..d37b7e99b368 100644 --- a/include/tools/diagnose_ex.h +++ b/include/tools/diagnose_ex.h @@ -133,6 +133,36 @@ inline css::uno::Any DbgGetCaughtException() */ TOOLS_DLLPUBLIC OString exceptionToString(css::uno::Any const & caughtEx); +/** + Logs an message along with a nicely formatted version of the current exception. + This must be called as the FIRST thing in a catch block. +*/ +#define TOOLS_WARN_EXCEPTION(area, stream) \ + do { \ + css::uno::Any tools_warn_exception( cppu::getCaughtException() ); \ + SAL_WARN(area, stream << " " << exceptionToString(tools_warn_exception)); \ + } while (false) + +/** + Logs an message along with a nicely formatted version of the current exception. + This must be called as the FIRST thing in a catch block. +*/ +#define TOOLS_WARN_EXCEPTION_IF(cond, area, stream) \ + do { \ + css::uno::Any tools_warn_exception( cppu::getCaughtException() ); \ + SAL_WARN_IF(cond, area, stream << " " << exceptionToString(tools_warn_exception)); \ + } while (false) + +/** + Logs an message along with a nicely formatted version of the current exception. + This must be called as the FIRST thing in a catch block. +*/ +#define TOOLS_INFO_EXCEPTION(area, stream) \ + do { \ + css::uno::Any tools_warn_exception( cppu::getCaughtException() ); \ + SAL_WARN(area, stream << " " << exceptionToString(tools_warn_exception)); \ + } while (false) + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3