/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ #ifndef INCLUDED_COMPHELPER_DIAGNOSE_EX_HXX #define INCLUDED_COMPHELPER_DIAGNOSE_EX_HXX
/** 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
*/ #ifdefined SAL_LOG_WARN #define DBG_UNHANDLED_EXCEPTION_0_ARGS() \
DbgUnhandledException( DbgGetCaughtException(), __func__, SAL_DETAIL_WHERE ); #define DBG_UNHANDLED_EXCEPTION_1_ARGS(area) \
DbgUnhandledException( DbgGetCaughtException(), __func__, SAL_DETAIL_WHERE, area ); #define DBG_UNHANDLED_EXCEPTION_2_ARGS(area, explanatory) \
DbgUnhandledException( DbgGetCaughtException(), __func__, SAL_DETAIL_WHERE, area, explanatory );
/** This macro asserts the given condition (in debug mode), and throws an IllegalArgumentException afterwards.
*/ #define ENSURE_ARG_OR_THROW(c, m) if( !(c) ) { \
OSL_ENSURE(c, m); \ throw css::lang::IllegalArgumentException( \
__func__ \
+ OUString::Concat(u",\n" m), \
css::uno::Reference< css::uno::XInterface >(), \
0 ); } #define ENSURE_ARG_OR_THROW2(c, m, ifc, arg) if( !(c) ) { \
OSL_ENSURE(c, m); \ throw css::lang::IllegalArgumentException( \
__func__ \
+ OUString::Concat(u",\n" m), \
ifc, \
arg ); }
/** This macro asserts the given condition (in debug mode), and throws a RuntimeException afterwards.
*/ #define ENSURE_OR_THROW(c, m) \ 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 returns the given value afterwards.
*/ #define ENSURE_OR_RETURN(c, m, r) if( !(c) ) { \
OSL_ENSURE(c, m); \ return r; }
/** This macro asserts the given condition (in debug mode), and returns false afterwards.
*/ #define ENSURE_OR_RETURN_FALSE(c, m) \
ENSURE_OR_RETURN(c, m, false)
/** This macro asserts the given condition (in debug mode), and returns afterwards, without return value "void".
*/ #define ENSURE_OR_RETURN_VOID( c, m ) \ if( !(c) ) \
{ \
OSL_ENSURE( c, m ); \ return; \
}
/** Convert a caught exception to a string suitable for logging.
*/
COMPHELPER_DLLPUBLIC OString exceptionToString(css::uno::Any const & caughtEx);
/** 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.
*/ #ifdefined SAL_LOG_WARN #define TOOLS_WARN_EXCEPTION(area, stream) \ do { \
css::uno::Any tools_warn_exception( DbgGetCaughtException() ); \
SAL_WARN(area, stream << " " << exceptionToString(tools_warn_exception)); \
} while (false) #else #define TOOLS_WARN_EXCEPTION(area, stream) \ do { \
SAL_WARN(area, stream); \
} while (false) #endif
/** 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.
*/ #ifdefined SAL_LOG_WARN #define TOOLS_WARN_EXCEPTION_IF(cond, area, stream) \ do { \
css::uno::Any tools_warn_exception( DbgGetCaughtException() ); \
SAL_WARN_IF(cond, area, stream << " " << exceptionToString(tools_warn_exception)); \
} while (false) #else #define TOOLS_WARN_EXCEPTION_IF(cond, area, stream) \ do { \
SAL_WARN_IF(cond, area, stream); \
} while (false) #endif
/** 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.
*/ #ifdefined SAL_LOG_INFO #define TOOLS_INFO_EXCEPTION(area, stream) \ do { \
css::uno::Any tools_warn_exception( DbgGetCaughtException() ); \
SAL_INFO(area, stream << " " << exceptionToString(tools_warn_exception)); \
} while (false) #else #define TOOLS_INFO_EXCEPTION(area, stream) \ do { \
SAL_INFO(area, stream); \
} while (false) #endif
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.