build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / include / tools / diagnose_ex.h
blobbd0ec8818ba9a0870d8a3ee2b4df4804ed8cb724
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/toolsdllapi.h>
30 TOOLS_DLLPUBLIC void DbgUnhandledException(const css::uno::Any& caughtException, const char* currentFunction, const char* fileAndLineNo);
32 #if OSL_DEBUG_LEVEL > 0
33 #include <com/sun/star/configuration/CorruptedConfigurationException.hpp>
34 #include <cppuhelper/exc_hlp.hxx>
35 #include <osl/diagnose.h>
36 #include <osl/thread.h>
38 /** reports a caught UNO exception via OSL diagnostics
40 Note that whenever you use this, it might be an indicator that your error
41 handling is not correct ....
43 #define DBG_UNHANDLED_EXCEPTION() \
44 DbgUnhandledException( ::cppu::getCaughtException(), OSL_THIS_FUNC, SAL_DETAIL_WHERE);
46 #else // OSL_DEBUG_LEVEL
47 #define DBG_UNHANDLED_EXCEPTION()
48 #endif // OSL_DEBUG_LEVEL
50 /** This macro asserts the given condition (in debug mode), and throws
51 an IllegalArgumentException afterwards.
53 #define ENSURE_ARG_OR_THROW(c, m) if( !(c) ) { \
54 OSL_ENSURE(c, m); \
55 throw css::lang::IllegalArgumentException( \
56 OUStringLiteral(OSL_THIS_FUNC) \
57 + ",\n" m, \
58 css::uno::Reference< css::uno::XInterface >(), \
59 0 ); }
60 #define ENSURE_ARG_OR_THROW2(c, m, ifc, arg) if( !(c) ) { \
61 OSL_ENSURE(c, m); \
62 throw css::lang::IllegalArgumentException( \
63 OUStringLiteral(OSL_THIS_FUNC) \
64 + ",\n" m, \
65 ifc, \
66 arg ); }
68 /** This macro asserts the given condition (in debug mode), and throws
69 an RuntimeException afterwards.
71 #define ENSURE_OR_THROW(c, m) \
72 if( !(c) ){ \
73 OSL_ENSURE(c, m); \
74 throw css::uno::RuntimeException( \
75 OUStringLiteral(OSL_THIS_FUNC) + ",\n" m, \
76 css::uno::Reference< css::uno::XInterface >() ); }
78 #define ENSURE_OR_THROW2(c, m, ifc) \
79 if( !(c) ) { \
80 OSL_ENSURE(c, m); \
81 throw css::uno::RuntimeException( \
82 OUStringLiteral(OSL_THIS_FUNC) + ",\n" m, \
83 ifc ); }
85 /** This macro asserts the given condition (in debug mode), and
86 returns the given value afterwards.
88 #define ENSURE_OR_RETURN(c, m, r) if( !(c) ) { \
89 OSL_ENSURE(c, m); \
90 return r; }
92 /** This macro asserts the given condition (in debug mode), and
93 returns false afterwards.
95 #define ENSURE_OR_RETURN_FALSE(c, m) \
96 ENSURE_OR_RETURN(c, m, false)
98 /** This macro asserts the given condition (in debug mode), and
99 returns afterwards, without return value "void".
101 #define ENSURE_OR_RETURN_VOID( c, m ) \
102 if( !(c) ) \
104 OSL_ENSURE( c, m ); \
105 return; \
110 /** This macro asserts the given condition (in debug mode), and
111 returns afterwards, without return value "void".
113 #define ENSURE_OR_RETURN_VOID( c, m ) \
114 if( !(c) ) \
116 OSL_ENSURE( c, m ); \
117 return; \
120 #endif
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */