LibreOffice Module comphelper (master) 1
Macros | Functions
diagnose_ex.hxx File Reference
#include <osl/diagnose.h>
#include <rtl/ustring.hxx>
#include <com/sun/star/uno/RuntimeException.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <sal/log.hxx>
#include <comphelper/comphelperdllapi.h>
#include <cppuhelper/exc_hlp.hxx>
Include dependency graph for diagnose_ex.hxx:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DBG_UNHANDLED_EXCEPTION(...)
 reports a caught UNO exception via OSL diagnostics More...
 
#define ENSURE_ARG_OR_THROW(c, m)
 This macro asserts the given condition (in debug mode), and throws an IllegalArgumentException afterwards. More...
 
#define ENSURE_ARG_OR_THROW2(c, m, ifc, arg)
 
#define ENSURE_OR_THROW(c, m)
 This macro asserts the given condition (in debug mode), and throws a RuntimeException afterwards. More...
 
#define ENSURE_OR_THROW2(c, m, ifc)
 
#define ENSURE_OR_RETURN(c, m, r)
 This macro asserts the given condition (in debug mode), and returns the given value afterwards. More...
 
#define ENSURE_OR_RETURN_FALSE(c, m)    ENSURE_OR_RETURN(c, m, false)
 This macro asserts the given condition (in debug mode), and returns false afterwards. More...
 
#define ENSURE_OR_RETURN_VOID(c, m)
 This macro asserts the given condition (in debug mode), and returns afterwards, without return value "void". More...
 
#define TOOLS_WARN_EXCEPTION(area, stream)
 Logs an message along with a nicely formatted version of the current exception. More...
 
#define TOOLS_WARN_EXCEPTION_IF(cond, area, stream)
 Logs an message along with a nicely formatted version of the current exception. More...
 
#define TOOLS_INFO_EXCEPTION(area, stream)
 Logs an message along with a nicely formatted version of the current exception. More...
 

Functions

COMPHELPER_DLLPUBLIC void DbgUnhandledException (const css::uno::Any &caughtException, const char *currentFunction, const char *fileAndLineNo, const char *area, const char *explanatory=nullptr)
 
css::uno::Any DbgGetCaughtException ()
 
COMPHELPER_DLLPUBLIC OString exceptionToString (css::uno::Any const &caughtEx)
 Convert a caught exception to a string suitable for logging. More...
 

Macro Definition Documentation

◆ DBG_UNHANDLED_EXCEPTION

#define DBG_UNHANDLED_EXCEPTION (   ...)

reports a caught UNO exception via OSL diagnostics

Note that whenever you use this, it might be an indicator that your error handling is not correct... This takes two optional parameters: area and explanatory

Definition at line 75 of file diagnose_ex.hxx.

◆ ENSURE_ARG_OR_THROW

#define ENSURE_ARG_OR_THROW (   c,
 
)
Value:
if( !(c) ) { \
OSL_ENSURE(c, m); \
throw css::lang::IllegalArgumentException( \
__func__ \
+ OUString::Concat(u",\n" m), \
css::uno::Reference< css::uno::XInterface >(), \
0 ); }

This macro asserts the given condition (in debug mode), and throws an IllegalArgumentException afterwards.

Definition at line 82 of file diagnose_ex.hxx.

◆ ENSURE_ARG_OR_THROW2

#define ENSURE_ARG_OR_THROW2 (   c,
  m,
  ifc,
  arg 
)
Value:
if( !(c) ) { \
OSL_ENSURE(c, m); \
throw css::lang::IllegalArgumentException( \
__func__ \
+ OUString::Concat(u",\n" m), \
ifc, \
arg ); }

Definition at line 89 of file diagnose_ex.hxx.

◆ ENSURE_OR_RETURN

#define ENSURE_OR_RETURN (   c,
  m,
 
)
Value:
if( !(c) ) { \
OSL_ENSURE(c, m); \
return r; }

This macro asserts the given condition (in debug mode), and returns the given value afterwards.

Definition at line 117 of file diagnose_ex.hxx.

◆ ENSURE_OR_RETURN_FALSE

#define ENSURE_OR_RETURN_FALSE (   c,
 
)     ENSURE_OR_RETURN(c, m, false)

This macro asserts the given condition (in debug mode), and returns false afterwards.

Definition at line 124 of file diagnose_ex.hxx.

◆ ENSURE_OR_RETURN_VOID

#define ENSURE_OR_RETURN_VOID (   c,
 
)
Value:
if( !(c) ) \
{ \
OSL_ENSURE( c, m ); \
return; \
}

This macro asserts the given condition (in debug mode), and returns afterwards, without return value "void".

Definition at line 130 of file diagnose_ex.hxx.

◆ ENSURE_OR_THROW

#define ENSURE_OR_THROW (   c,
 
)
Value:
if( !(c) ){ \
OSL_ENSURE(c, m); \
throw css::uno::RuntimeException( \
__func__ + OUString::Concat(u",\n" m), \
css::uno::Reference< css::uno::XInterface >() ); }

This macro asserts the given condition (in debug mode), and throws a RuntimeException afterwards.

Definition at line 100 of file diagnose_ex.hxx.

◆ ENSURE_OR_THROW2

#define ENSURE_OR_THROW2 (   c,
  m,
  ifc 
)
Value:
if( !(c) ) { \
OSL_ENSURE(c, m); \
throw css::uno::RuntimeException( \
__func__ + OUString::Concat(u",\n" m), \
ifc ); }

Definition at line 107 of file diagnose_ex.hxx.

◆ TOOLS_INFO_EXCEPTION

#define TOOLS_INFO_EXCEPTION (   area,
  stream 
)
Value:
do { \
SAL_INFO(area, stream); \
} 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.

Definition at line 186 of file diagnose_ex.hxx.

◆ TOOLS_WARN_EXCEPTION

#define TOOLS_WARN_EXCEPTION (   area,
  stream 
)
Value:
do { \
SAL_WARN(area, stream); \
} 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.

Definition at line 152 of file diagnose_ex.hxx.

◆ TOOLS_WARN_EXCEPTION_IF

#define TOOLS_WARN_EXCEPTION_IF (   cond,
  area,
  stream 
)
Value:
do { \
SAL_WARN_IF(cond, area, stream); \
} 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.

Definition at line 169 of file diagnose_ex.hxx.

Function Documentation

◆ DbgGetCaughtException()

css::uno::Any DbgGetCaughtException ( )
inline

Definition at line 38 of file diagnose_ex.hxx.

◆ DbgUnhandledException()

COMPHELPER_DLLPUBLIC void DbgUnhandledException ( const css::uno::Any caughtException,
const char *  currentFunction,
const char *  fileAndLineNo,
const char *  area,
const char *  explanatory = nullptr 
)

Definition at line 371 of file diagnose_ex.cxx.

References exceptionToStringImpl(), and sMessage.

◆ exceptionToString()

COMPHELPER_DLLPUBLIC OString exceptionToString ( css::uno::Any const &  caughtEx)

Convert a caught exception to a string suitable for logging.

Definition at line 364 of file diagnose_ex.cxx.

References exceptionToStringImpl(), and sMessage.

Referenced by exceptionToStringImpl().