Don't search for old (<= 2.0) .NET SDK anymore
[LibreOffice.git] / include / tools / diagnose_ex.h
blob0f924fc2098846f4f44deab51f6cb728a5dab588
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>
29 #include <cppuhelper/exc_hlp.hxx>
30 #include <osl/thread.h>
32 TOOLS_DLLPUBLIC void DbgUnhandledException(const css::uno::Any& caughtException,
33 const char* currentFunction, const char* fileAndLineNo,
34 const char* area, const char* explanatory = nullptr);
36 //getCaughtException throws exceptions in never-going-to-happen situations which
37 //floods coverity with warnings
38 inline css::uno::Any DbgGetCaughtException()
40 #if defined(__COVERITY__)
41 try
43 return ::cppu::getCaughtException();
45 catch (...)
47 std::abort();
49 #else
50 return ::cppu::getCaughtException();
51 #endif
54 /** reports a caught UNO exception via OSL diagnostics
56 Note that whenever you use this, it might be an indicator that your error
57 handling is not correct ....
58 This takes two optional parameters: area and explanatory
60 #define DBG_UNHANDLED_EXCEPTION_0_ARGS() \
61 DbgUnhandledException( DbgGetCaughtException(), OSL_THIS_FUNC, SAL_DETAIL_WHERE );
62 #define DBG_UNHANDLED_EXCEPTION_1_ARGS(area) \
63 DbgUnhandledException( DbgGetCaughtException(), OSL_THIS_FUNC, SAL_DETAIL_WHERE, area );
64 #define DBG_UNHANDLED_EXCEPTION_2_ARGS(area, explanatory) \
65 DbgUnhandledException( DbgGetCaughtException(), OSL_THIS_FUNC, SAL_DETAIL_WHERE, area, explanatory );
67 #define DBG_UNHANDLED_FUNC_CHOOSER(_f1, _f2, _f3, ...) _f3
68 #define DBG_UNHANDLED_FUNC_RECOMPOSER(argsWithParentheses) DBG_UNHANDLED_FUNC_CHOOSER argsWithParentheses
69 #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, ))
70 #define DBG_UNHANDLED_NO_ARG_EXPANDER() ,,DBG_UNHANDLED_EXCEPTION_0_ARGS
71 #define DBG_UNHANDLED_MACRO_CHOOSER(...) DBG_UNHANDLED_CHOOSE_FROM_ARG_COUNT(DBG_UNHANDLED_NO_ARG_EXPANDER __VA_ARGS__ ())
72 #define DBG_UNHANDLED_EXCEPTION(...) DBG_UNHANDLED_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
75 /** This macro asserts the given condition (in debug mode), and throws
76 an IllegalArgumentException afterwards.
78 #define ENSURE_ARG_OR_THROW(c, m) if( !(c) ) { \
79 OSL_ENSURE(c, m); \
80 throw css::lang::IllegalArgumentException( \
81 OUStringLiteral(OSL_THIS_FUNC) \
82 + ",\n" m, \
83 css::uno::Reference< css::uno::XInterface >(), \
84 0 ); }
85 #define ENSURE_ARG_OR_THROW2(c, m, ifc, arg) if( !(c) ) { \
86 OSL_ENSURE(c, m); \
87 throw css::lang::IllegalArgumentException( \
88 OUStringLiteral(OSL_THIS_FUNC) \
89 + ",\n" m, \
90 ifc, \
91 arg ); }
93 /** This macro asserts the given condition (in debug mode), and throws
94 an RuntimeException afterwards.
96 #define ENSURE_OR_THROW(c, m) \
97 if( !(c) ){ \
98 OSL_ENSURE(c, m); \
99 throw css::uno::RuntimeException( \
100 OUStringLiteral(OSL_THIS_FUNC) + ",\n" m, \
101 css::uno::Reference< css::uno::XInterface >() ); }
103 #define ENSURE_OR_THROW2(c, m, ifc) \
104 if( !(c) ) { \
105 OSL_ENSURE(c, m); \
106 throw css::uno::RuntimeException( \
107 OUStringLiteral(OSL_THIS_FUNC) + ",\n" m, \
108 ifc ); }
110 /** This macro asserts the given condition (in debug mode), and
111 returns the given value afterwards.
113 #define ENSURE_OR_RETURN(c, m, r) if( !(c) ) { \
114 OSL_ENSURE(c, m); \
115 return r; }
117 /** This macro asserts the given condition (in debug mode), and
118 returns false afterwards.
120 #define ENSURE_OR_RETURN_FALSE(c, m) \
121 ENSURE_OR_RETURN(c, m, false)
123 /** This macro asserts the given condition (in debug mode), and
124 returns afterwards, without return value "void".
126 #define ENSURE_OR_RETURN_VOID( c, m ) \
127 if( !(c) ) \
129 OSL_ENSURE( c, m ); \
130 return; \
133 #endif
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */