19#ifndef INCLUDED_COMPHELPER_DIAGNOSE_EX_HXX
20#define INCLUDED_COMPHELPER_DIAGNOSE_EX_HXX
22#include <osl/diagnose.h>
23#include <rtl/ustring.hxx>
25#include <com/sun/star/uno/RuntimeException.hpp>
26#include <com/sun/star/lang/IllegalArgumentException.hpp>
33 const char* currentFunction,
const char* fileAndLineNo,
34 const char* area,
const char* explanatory =
nullptr);
40#if defined(__COVERITY__)
43 return ::cppu::getCaughtException();
50 return ::cppu::getCaughtException();
60#if defined SAL_LOG_WARN
61#define DBG_UNHANDLED_EXCEPTION_0_ARGS() \
62 DbgUnhandledException( DbgGetCaughtException(), __func__, SAL_DETAIL_WHERE );
63#define DBG_UNHANDLED_EXCEPTION_1_ARGS(area) \
64 DbgUnhandledException( DbgGetCaughtException(), __func__, SAL_DETAIL_WHERE, area );
65#define DBG_UNHANDLED_EXCEPTION_2_ARGS(area, explanatory) \
66 DbgUnhandledException( DbgGetCaughtException(), __func__, SAL_DETAIL_WHERE, area, explanatory );
68#define DBG_UNHANDLED_FUNC_CHOOSER(_f1, _f2, _f3, ...) _f3
69#define DBG_UNHANDLED_FUNC_RECOMPOSER(argsWithParentheses) DBG_UNHANDLED_FUNC_CHOOSER argsWithParentheses
70#define DBG_UNHANDLED_CHOOSE_FROM_ARG_COUNT(...) DBG_UNHANDLED_FUNC_RECOMPOSER((__VA_ARGS__, DBG_UNHANDLED_EXCEPTION_2_ARGS, DBG_UNHANDLED_EXCEPTION_1_ARGS, DBG_UNHANDLED_EXCEPTION_0_ARGS, ))
71#define DBG_UNHANDLED_NO_ARG_EXPANDER() ,,DBG_UNHANDLED_EXCEPTION_0_ARGS
72#define DBG_UNHANDLED_MACRO_CHOOSER(...) DBG_UNHANDLED_CHOOSE_FROM_ARG_COUNT(DBG_UNHANDLED_NO_ARG_EXPANDER __VA_ARGS__ ())
73#define DBG_UNHANDLED_EXCEPTION(...) DBG_UNHANDLED_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
75#define DBG_UNHANDLED_EXCEPTION(...)
82#define ENSURE_ARG_OR_THROW(c, m) if( !(c) ) { \
84 throw css::lang::IllegalArgumentException( \
86 + OUString::Concat(u",\n" m), \
87 css::uno::Reference< css::uno::XInterface >(), \
89#define ENSURE_ARG_OR_THROW2(c, m, ifc, arg) if( !(c) ) { \
91 throw css::lang::IllegalArgumentException( \
93 + OUString::Concat(u",\n" m), \
100#define ENSURE_OR_THROW(c, m) \
103 throw css::uno::RuntimeException( \
104 __func__ + OUString::Concat(u",\n" m), \
105 css::uno::Reference< css::uno::XInterface >() ); }
107#define ENSURE_OR_THROW2(c, m, ifc) \
110 throw css::uno::RuntimeException( \
111 __func__ + OUString::Concat(u",\n" m), \
117#define ENSURE_OR_RETURN(c, m, r) if( !(c) ) { \
124#define ENSURE_OR_RETURN_FALSE(c, m) \
125 ENSURE_OR_RETURN(c, m, false)
130#define ENSURE_OR_RETURN_VOID( c, m ) \
133 OSL_ENSURE( c, m ); \
145#if defined SAL_LOG_WARN
146#define TOOLS_WARN_EXCEPTION(area, stream) \
148 css::uno::Any tools_warn_exception( DbgGetCaughtException() ); \
149 SAL_WARN(area, stream << " " << exceptionToString(tools_warn_exception)); \
152#define TOOLS_WARN_EXCEPTION(area, stream) \
154 SAL_WARN(area, stream); \
162#if defined SAL_LOG_WARN
163#define TOOLS_WARN_EXCEPTION_IF(cond, area, stream) \
165 css::uno::Any tools_warn_exception( DbgGetCaughtException() ); \
166 SAL_WARN_IF(cond, area, stream << " " << exceptionToString(tools_warn_exception)); \
169#define TOOLS_WARN_EXCEPTION_IF(cond, area, stream) \
171 SAL_WARN_IF(cond, area, stream); \
179#if defined SAL_LOG_INFO
180#define TOOLS_INFO_EXCEPTION(area, stream) \
182 css::uno::Any tools_warn_exception( DbgGetCaughtException() ); \
183 SAL_INFO(area, stream << " " << exceptionToString(tools_warn_exception)); \
186#define TOOLS_INFO_EXCEPTION(area, stream) \
188 SAL_INFO(area, stream); \
#define COMPHELPER_DLLPUBLIC
css::uno::Any DbgGetCaughtException()
COMPHELPER_DLLPUBLIC void DbgUnhandledException(const css::uno::Any &caughtException, const char *currentFunction, const char *fileAndLineNo, const char *area, const char *explanatory=nullptr)
COMPHELPER_DLLPUBLIC OString exceptionToString(css::uno::Any const &caughtEx)
Convert a caught exception to a string suitable for logging.