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 .
20 #include <com/sun/star/configuration/CorruptedConfigurationException.hpp>
21 #include <com/sun/star/configuration/backend/BackendSetupException.hpp>
22 #include <com/sun/star/configuration/backend/MalformedDataException.hpp>
23 #include <com/sun/star/configuration/InvalidBootstrapFileException.hpp>
24 #include <com/sun/star/configuration/MissingBootstrapFileException.hpp>
25 #include <com/sun/star/deployment/DependencyException.hpp>
26 #include <com/sun/star/deployment/DeploymentException.hpp>
27 #include <com/sun/star/document/CorruptedFilterConfigurationException.hpp>
28 #include <com/sun/star/document/UndoFailedException.hpp>
29 #include <com/sun/star/lang/IllegalArgumentException.hpp>
30 #include <com/sun/star/lang/WrappedTargetException.hpp>
31 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
32 #include <com/sun/star/ldap/LdapGenericException.hpp>
33 #include <com/sun/star/script/BasicErrorException.hpp>
34 #include <com/sun/star/script/CannotConvertException.hpp>
35 #include <com/sun/star/script/provider/ScriptExceptionRaisedException.hpp>
36 #include <com/sun/star/script/provider/ScriptFrameworkErrorException.hpp>
37 #include <com/sun/star/sdbc/SQLException.hpp>
38 #include <com/sun/star/system/SystemShellExecuteException.hpp>
39 #include <com/sun/star/task/ErrorCodeIOException.hpp>
40 #include <com/sun/star/ucb/CommandFailedException.hpp>
41 #include <com/sun/star/ucb/ContentCreationException.hpp>
42 #include <com/sun/star/ucb/MissingPropertiesException.hpp>
43 #include <com/sun/star/ucb/NameClashException.hpp>
44 #include <com/sun/star/ucb/InteractiveIOException.hpp>
45 #include <com/sun/star/util/MalformedNumberFormatException.hpp>
46 #include <com/sun/star/xml/dom/DOMException.hpp>
47 #include <com/sun/star/xml/sax/SAXException.hpp>
48 #include <com/sun/star/xml/sax/SAXParseException.hpp>
49 #include <comphelper/anytostring.hxx>
50 #include <tools/debug.hxx>
51 #include <sal/log.hxx>
52 #include <osl/thread.h>
53 #include <rtl/strbuf.hxx>
58 #include <tools/diagnose_ex.h>
60 #if defined __GLIBCXX__
68 DbgTestSolarMutexProc pDbgTestSolarMutex
;
69 bool bTestSolarMutexWasSet
;
72 :pDbgTestSolarMutex( nullptr ), bTestSolarMutexWasSet(false)
77 static DebugData aDebugData
;
79 void DbgSetTestSolarMutex( DbgTestSolarMutexProc pParam
)
81 aDebugData
.pDbgTestSolarMutex
= pParam
;
83 aDebugData
.bTestSolarMutexWasSet
= true;
86 void DbgTestSolarMutex()
88 // don't warn if it was set at least once, because then we're probably just post-DeInitVCL()
90 !aDebugData
.bTestSolarMutexWasSet
&& aDebugData
.pDbgTestSolarMutex
== nullptr, "tools.debug",
91 "no DbgTestSolarMutex function set");
92 if ( aDebugData
.pDbgTestSolarMutex
)
93 aDebugData
.pDbgTestSolarMutex();
98 static void exceptionToStringImpl(OStringBuffer
& sMessage
, const css::uno::Any
& caught
)
100 auto toOString
= [](OUString
const & s
) {
101 return OUStringToOString( s
, osl_getThreadTextEncoding() );
103 sMessage
.append(toOString(caught
.getValueTypeName()));
104 css::uno::Exception exception
;
105 caught
>>= exception
;
106 if ( !exception
.Message
.isEmpty() )
108 sMessage
.append(" message: ");
109 sMessage
.append(toOString(exception
.Message
));
111 if ( exception
.Context
.is() )
113 const char* pContext
= typeid( *exception
.Context
).name();
114 #if defined __GLIBCXX__
115 // demangle the type name, not necessary under windows, we already get demangled names there
117 pContext
= abi::__cxa_demangle( pContext
, nullptr, nullptr, &status
);
119 sMessage
.append(" context: ");
120 sMessage
.append(pContext
);
121 #if defined __GLIBCXX__
122 std::free(const_cast<char *>(pContext
));
126 css::configuration::CorruptedConfigurationException specialized
;
127 if ( caught
>>= specialized
)
129 sMessage
.append(" details: ");
130 sMessage
.append(toOString(specialized
.Details
));
134 css::configuration::InvalidBootstrapFileException specialized
;
135 if ( caught
>>= specialized
)
137 sMessage
.append(" BootstrapFileURL: ");
138 sMessage
.append(toOString(specialized
.BootstrapFileURL
));
142 css::configuration::MissingBootstrapFileException specialized
;
143 if ( caught
>>= specialized
)
145 sMessage
.append(" BootstrapFileURL: ");
146 sMessage
.append(toOString(specialized
.BootstrapFileURL
));
150 css::configuration::backend::MalformedDataException specialized
;
151 if ( caught
>>= specialized
)
153 sMessage
.append("\n wrapped: ");
154 sMessage
.append(exceptionToString(specialized
.ErrorDetails
));
158 css::configuration::backend::BackendSetupException specialized
;
159 if ( caught
>>= specialized
)
161 sMessage
.append("\n wrapped: ");
162 sMessage
.append(exceptionToString(specialized
.BackendException
));
166 css::deployment::DependencyException specialized
;
167 if ( caught
>>= specialized
)
169 sMessage
.append(" UnsatisfiedDependencies: ");
170 sMessage
.append(toOString(comphelper::anyToString(css::uno::Any(specialized
.UnsatisfiedDependencies
))));
174 css::deployment::DeploymentException specialized
;
175 if ( caught
>>= specialized
)
177 sMessage
.append("\n wrapped: ");
178 sMessage
.append(exceptionToString(specialized
.Cause
));
182 css::document::CorruptedFilterConfigurationException specialized
;
183 if ( caught
>>= specialized
)
185 sMessage
.append(" Details: ");
186 sMessage
.append(toOString(specialized
.Details
));
190 css::document::UndoFailedException specialized
;
191 if ( caught
>>= specialized
)
193 sMessage
.append(" Reason: ");
194 sMessage
.append(toOString(comphelper::anyToString(specialized
.Reason
)));
198 css::lang::IllegalArgumentException specialized
;
199 if ( caught
>>= specialized
)
201 sMessage
.append(" ArgumentPosition: ");
202 sMessage
.append(OString::number(specialized
.ArgumentPosition
));
206 css::lang::WrappedTargetException specialized
;
207 if ( caught
>>= specialized
)
209 sMessage
.append("\n wrapped: ");
210 sMessage
.append(exceptionToString(specialized
.TargetException
));
214 css::lang::WrappedTargetRuntimeException specialized
;
215 if ( caught
>>= specialized
)
217 sMessage
.append("\n wrapped: ");
218 sMessage
.append(exceptionToString(specialized
.TargetException
));
222 css::ldap::LdapGenericException specialized
;
223 if ( caught
>>= specialized
)
225 sMessage
.append(" ErrorCode: ");
226 sMessage
.append(OString::number(specialized
.ErrorCode
));
230 css::script::BasicErrorException specialized
;
231 if ( caught
>>= specialized
)
233 sMessage
.append(" ErrorCode: ");
234 sMessage
.append(OString::number(specialized
.ErrorCode
));
235 sMessage
.append(" ErrorMessageArgument: ");
236 sMessage
.append(toOString(specialized
.ErrorMessageArgument
));
240 css::script::CannotConvertException specialized
;
241 if ( caught
>>= specialized
)
243 sMessage
.append(" DestinationTypeClass: ");
244 sMessage
.append(toOString(comphelper::anyToString(css::uno::Any(specialized
.DestinationTypeClass
))));
245 sMessage
.append(" Reason: ");
246 sMessage
.append(OString::number(specialized
.Reason
));
247 sMessage
.append(" ArgumentIndex: ");
248 sMessage
.append(OString::number(specialized
.ArgumentIndex
));
252 css::script::provider::ScriptErrorRaisedException specialized
;
253 if ( caught
>>= specialized
)
255 sMessage
.append(" scriptName: ");
256 sMessage
.append(toOString(specialized
.scriptName
));
257 sMessage
.append(" language: ");
258 sMessage
.append(toOString(specialized
.language
));
259 sMessage
.append(" lineNum: ");
260 sMessage
.append(OString::number(specialized
.lineNum
));
264 css::script::provider::ScriptExceptionRaisedException specialized
;
265 if ( caught
>>= specialized
)
267 sMessage
.append(" exceptionType: ");
268 sMessage
.append(toOString(specialized
.exceptionType
));
272 css::script::provider::ScriptFrameworkErrorException specialized
;
273 if ( caught
>>= specialized
)
275 sMessage
.append(" scriptName: ");
276 sMessage
.append(toOString(specialized
.scriptName
));
277 sMessage
.append(" language: ");
278 sMessage
.append(toOString(specialized
.language
));
279 sMessage
.append(" errorType: ");
280 sMessage
.append(OString::number(specialized
.errorType
));
284 css::sdbc::SQLException specialized
;
285 if ( caught
>>= specialized
)
287 sMessage
.append(" SQLState: ");
288 sMessage
.append(toOString(specialized
.SQLState
));
289 sMessage
.append(" ErrorCode: ");
290 sMessage
.append(OString::number(specialized
.ErrorCode
));
291 sMessage
.append("\n wrapped: ");
292 sMessage
.append(exceptionToString(specialized
.NextException
));
296 css::system::SystemShellExecuteException specialized
;
297 if ( caught
>>= specialized
)
299 sMessage
.append(" PosixError: ");
300 sMessage
.append(OString::number(specialized
.PosixError
));
304 css::task::ErrorCodeIOException specialized
;
305 if ( caught
>>= specialized
)
307 sMessage
.append(" errcode: ");
308 sMessage
.append(OString::number( specialized
.ErrCode
));
312 css::ucb::CommandFailedException specialized
;
313 if ( caught
>>= specialized
)
315 sMessage
.append("\n Reason: ");
316 sMessage
.append(exceptionToString( specialized
.Reason
));
320 css::ucb::ContentCreationException specialized
;
321 if ( caught
>>= specialized
)
323 sMessage
.append(" eError: ");
324 sMessage
.append(toOString(comphelper::anyToString( css::uno::Any(specialized
.eError
) )));
328 css::ucb::MissingPropertiesException specialized
;
329 if ( caught
>>= specialized
)
331 sMessage
.append(" Properties: ");
332 sMessage
.append(toOString(comphelper::anyToString( css::uno::Any(specialized
.Properties
) )));
336 css::ucb::NameClashException specialized
;
337 if ( caught
>>= specialized
)
339 sMessage
.append(" Name: ");
340 sMessage
.append(toOString( specialized
.Name
));
344 css::util::MalformedNumberFormatException specialized
;
345 if ( caught
>>= specialized
)
347 sMessage
.append(" CheckPos: ");
348 sMessage
.append(OString::number( specialized
.CheckPos
));
352 css::xml::dom::DOMException specialized
;
353 if ( caught
>>= specialized
)
355 sMessage
.append(" Code: ");
356 sMessage
.append(toOString(comphelper::anyToString( css::uno::Any(specialized
.Code
) )));
360 css::xml::dom::DOMException specialized
;
361 if ( caught
>>= specialized
)
363 sMessage
.append(" Code: ");
364 sMessage
.append(toOString(comphelper::anyToString( css::uno::Any(specialized
.Code
) )));
368 css::xml::sax::SAXException specialized
;
369 if ( caught
>>= specialized
)
371 sMessage
.append("\n wrapped: ");
372 sMessage
.append(exceptionToString( specialized
.WrappedException
));
376 css::xml::sax::SAXParseException specialized
;
377 if ( caught
>>= specialized
)
379 sMessage
.append(" PublicId: ");
380 sMessage
.append(toOString( specialized
.PublicId
));
381 sMessage
.append(" SystemId: ");
382 sMessage
.append(toOString( specialized
.SystemId
));
383 sMessage
.append(" LineNumber: ");
384 sMessage
.append(OString::number( specialized
.LineNumber
));
385 sMessage
.append(" ColumnNumber: ");
386 sMessage
.append(OString::number( specialized
.ColumnNumber
));
390 css::ucb::InteractiveIOException specialized
;
391 if ( caught
>>= specialized
)
393 sMessage
.append(" Code: ");
394 sMessage
.append(OString::number( static_cast<sal_Int32
>(specialized
.Code
) ));
399 OString
exceptionToString(const css::uno::Any
& caught
)
401 OStringBuffer
sMessage(512);
402 exceptionToStringImpl(sMessage
, caught
);
403 return sMessage
.makeStringAndClear();
406 void DbgUnhandledException(const css::uno::Any
& caught
, const char* currentFunction
, const char* fileAndLineNo
,
407 const char* area
, const char* explanatory
)
409 OStringBuffer
sMessage( 512 );
410 sMessage
.append( "DBG_UNHANDLED_EXCEPTION in " );
411 sMessage
.append(currentFunction
);
414 sMessage
.append("\n when: ");
415 sMessage
.append(explanatory
);
417 sMessage
.append(" exception: ");
418 exceptionToStringImpl(sMessage
, caught
);
423 SAL_DETAIL_LOG_FORMAT(
424 SAL_DETAIL_ENABLE_LOG_WARN
, SAL_DETAIL_LOG_LEVEL_WARN
,
425 area
, fileAndLineNo
, "%s", sMessage
.getStr());
428 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */