1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_TOOLS_DIAGNOSE_EX_H
20 #define INCLUDED_TOOLS_DIAGNOSE_EX_H
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>
28 #include <boost/current_function.hpp>
30 #define OSL_UNUSED( expression ) \
35 #if OSL_DEBUG_LEVEL > 0
36 #include <com/sun/star/configuration/CorruptedConfigurationException.hpp>
37 #include <cppuhelper/exc_hlp.hxx>
38 #include <osl/diagnose.h>
39 #include <osl/thread.h>
40 #include <boost/current_function.hpp>
42 #include <tools/toolsdllapi.h>
44 TOOLS_DLLPUBLIC
void DbgUnhandledException(const ::com::sun::star::uno::Any
& caughtException
, const char* currentFunction
, const char* fileAndLineNo
);
46 /** reports a caught UNO exception via OSL diagnostics
48 Note that whenever you use this, it might be an indicator that your error
49 handling is not correct ....
51 #define DBG_UNHANDLED_EXCEPTION() \
52 DbgUnhandledException( ::cppu::getCaughtException(), BOOST_CURRENT_FUNCTION, SAL_DETAIL_WHERE);
54 #else // OSL_DEBUG_LEVEL
55 #define DBG_UNHANDLED_EXCEPTION()
56 #endif // OSL_DEBUG_LEVEL
58 /** This macro asserts the given condition (in debug mode), and throws
59 an IllegalArgumentException afterwards.
61 #define ENSURE_ARG_OR_THROW(c, m) if( !(c) ) { \
63 throw ::com::sun::star::lang::IllegalArgumentException( \
64 OUStringLiteral(BOOST_CURRENT_FUNCTION) \
66 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(), \
68 #define ENSURE_ARG_OR_THROW2(c, m, ifc, arg) if( !(c) ) { \
70 throw ::com::sun::star::lang::IllegalArgumentException( \
71 OUStringLiteral(BOOST_CURRENT_FUNCTION) \
76 /** This macro asserts the given condition (in debug mode), and throws
77 an RuntimeException afterwards.
79 #define ENSURE_OR_THROW(c, m) \
82 throw ::com::sun::star::uno::RuntimeException( \
83 OUStringLiteral(BOOST_CURRENT_FUNCTION) + ",\n" m, \
84 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() ); }
86 #define ENSURE_OR_THROW2(c, m, ifc) \
89 throw ::com::sun::star::uno::RuntimeException( \
90 OUStringLiteral(BOOST_CURRENT_FUNCTION) + ",\n" m, \
93 /** This macro asserts the given condition (in debug mode), and
94 returns the given value afterwards.
96 #define ENSURE_OR_RETURN(c, m, r) if( !(c) ) { \
100 /** This macro asserts the given condition (in debug mode), and
101 returns false afterwards.
103 #define ENSURE_OR_RETURN_FALSE(c, m) \
104 ENSURE_OR_RETURN(c, m, false)
106 /** This macro asserts the given condition (in debug mode), and
107 returns afterwards, without return value "void".
109 #define ENSURE_OR_RETURN_VOID( c, m ) \
112 OSL_ENSURE( c, m ); \
118 /** This macro asserts the given condition (in debug mode), and
119 returns afterwards, without return value "void".
121 #define ENSURE_OR_RETURN_VOID( c, m ) \
124 OSL_ENSURE( c, m ); \
128 /** asserts a given condition (in debug mode), and continues the most-inner
129 loop if the condition is not met
131 #define ENSURE_OR_CONTINUE( c, m ) \
134 OSL_ENSURE( false, m ); \
138 /** asserts a given condition (in debug mode), and continues the most-inner
139 loop if the condition is not met
141 #define ENSURE_OR_BREAK( c, m ) \
144 OSL_ENSURE( false, m ); \
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */