android: Update app-specific/MIME type icons
[LibreOffice.git] / comphelper / source / misc / diagnose_ex.cxx
blobe805c5b4c2a5635986e6729f3d0ea487f04d76f7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 .
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 <sal/log.hxx>
51 #include <osl/thread.h>
52 #include <rtl/strbuf.hxx>
54 #include <comphelper/diagnose_ex.hxx>
56 #if defined __GLIBCXX__
57 #include <cxxabi.h>
58 #endif
60 static void exceptionToStringImpl(OStringBuffer& sMessage, const css::uno::Any & caught)
62 auto toOString = [](OUString const & s) {
63 return OUStringToOString( s, osl_getThreadTextEncoding() );
65 sMessage.append(toOString(caught.getValueTypeName()));
66 css::uno::Exception exception;
67 caught >>= exception;
68 if ( !exception.Message.isEmpty() )
70 sMessage.append(" message: \"");
71 sMessage.append(toOString(exception.Message));
72 sMessage.append("\"");
74 if ( exception.Context.is() )
76 const char* pContext = typeid( *exception.Context ).name();
77 #if defined __GLIBCXX__
78 // demangle the type name, not necessary under windows, we already get demangled names there
79 int status;
80 pContext = abi::__cxa_demangle( pContext, nullptr, nullptr, &status);
81 #endif
82 sMessage.append(" context: ");
83 sMessage.append(pContext);
84 #if defined __GLIBCXX__
85 std::free(const_cast<char *>(pContext));
86 #endif
89 css::configuration::CorruptedConfigurationException specialized;
90 if ( caught >>= specialized )
92 sMessage.append(" details: ");
93 sMessage.append(toOString(specialized.Details));
97 css::configuration::InvalidBootstrapFileException specialized;
98 if ( caught >>= specialized )
100 sMessage.append(" BootstrapFileURL: ");
101 sMessage.append(toOString(specialized.BootstrapFileURL));
105 css::configuration::MissingBootstrapFileException specialized;
106 if ( caught >>= specialized )
108 sMessage.append(" BootstrapFileURL: ");
109 sMessage.append(toOString(specialized.BootstrapFileURL));
113 css::configuration::backend::MalformedDataException specialized;
114 if ( caught >>= specialized )
116 sMessage.append("\n wrapped: ");
117 sMessage.append(exceptionToString(specialized.ErrorDetails));
121 css::configuration::backend::BackendSetupException specialized;
122 if ( caught >>= specialized )
124 sMessage.append("\n wrapped: ");
125 sMessage.append(exceptionToString(specialized.BackendException));
129 css::deployment::DependencyException specialized;
130 if ( caught >>= specialized )
132 sMessage.append(" UnsatisfiedDependencies: ");
133 sMessage.append(toOString(comphelper::anyToString(css::uno::Any(specialized.UnsatisfiedDependencies))));
137 css::deployment::DeploymentException specialized;
138 if ( caught >>= specialized )
140 sMessage.append("\n wrapped: ");
141 sMessage.append(exceptionToString(specialized.Cause));
145 css::document::CorruptedFilterConfigurationException specialized;
146 if ( caught >>= specialized )
148 sMessage.append(" Details: ");
149 sMessage.append(toOString(specialized.Details));
153 css::document::UndoFailedException specialized;
154 if ( caught >>= specialized )
156 sMessage.append(" Reason: ");
157 sMessage.append(toOString(comphelper::anyToString(specialized.Reason)));
161 css::lang::IllegalArgumentException specialized;
162 if ( caught >>= specialized )
164 sMessage.append(" ArgumentPosition: ");
165 sMessage.append(static_cast<sal_Int32>(specialized.ArgumentPosition));
169 css::lang::WrappedTargetException specialized;
170 if ( caught >>= specialized )
172 sMessage.append("\n wrapped: ");
173 sMessage.append(exceptionToString(specialized.TargetException));
177 css::lang::WrappedTargetRuntimeException specialized;
178 if ( caught >>= specialized )
180 sMessage.append("\n wrapped: ");
181 sMessage.append(exceptionToString(specialized.TargetException));
185 css::ldap::LdapGenericException specialized;
186 if ( caught >>= specialized )
188 sMessage.append(" ErrorCode: ");
189 sMessage.append(specialized.ErrorCode);
193 css::script::BasicErrorException specialized;
194 if ( caught >>= specialized )
196 sMessage.append(" ErrorCode: ");
197 sMessage.append(specialized.ErrorCode);
198 sMessage.append(" ErrorMessageArgument: ");
199 sMessage.append(toOString(specialized.ErrorMessageArgument));
203 css::script::CannotConvertException specialized;
204 if ( caught >>= specialized )
206 sMessage.append(" DestinationTypeClass: ");
207 sMessage.append(toOString(comphelper::anyToString(css::uno::Any(specialized.DestinationTypeClass))));
208 sMessage.append(" Reason: ");
209 sMessage.append(specialized.Reason);
210 sMessage.append(" ArgumentIndex: ");
211 sMessage.append(specialized.ArgumentIndex);
215 css::script::provider::ScriptErrorRaisedException specialized;
216 if ( caught >>= specialized )
218 sMessage.append(" scriptName: ");
219 sMessage.append(toOString(specialized.scriptName));
220 sMessage.append(" language: ");
221 sMessage.append(toOString(specialized.language));
222 sMessage.append(" lineNum: ");
223 sMessage.append(specialized.lineNum);
227 css::script::provider::ScriptExceptionRaisedException specialized;
228 if ( caught >>= specialized )
230 sMessage.append(" exceptionType: ");
231 sMessage.append(toOString(specialized.exceptionType));
235 css::script::provider::ScriptFrameworkErrorException specialized;
236 if ( caught >>= specialized )
238 sMessage.append(" scriptName: ");
239 sMessage.append(toOString(specialized.scriptName));
240 sMessage.append(" language: ");
241 sMessage.append(toOString(specialized.language));
242 sMessage.append(" errorType: ");
243 sMessage.append(specialized.errorType);
247 css::sdbc::SQLException specialized;
248 if ( caught >>= specialized )
250 sMessage.append(" SQLState: ");
251 sMessage.append(toOString(specialized.SQLState));
252 sMessage.append(" ErrorCode: ");
253 sMessage.append(specialized.ErrorCode);
254 sMessage.append("\n wrapped: ");
255 sMessage.append(exceptionToString(specialized.NextException));
259 css::system::SystemShellExecuteException specialized;
260 if ( caught >>= specialized )
262 sMessage.append(" PosixError: ");
263 sMessage.append(specialized.PosixError);
267 css::task::ErrorCodeIOException specialized;
268 if ( caught >>= specialized )
270 sMessage.append(" errcode: ");
271 sMessage.append( specialized.ErrCode );
275 css::ucb::CommandFailedException specialized;
276 if ( caught >>= specialized )
278 sMessage.append("\n Reason: ");
279 sMessage.append(exceptionToString( specialized.Reason ));
283 css::ucb::ContentCreationException specialized;
284 if ( caught >>= specialized )
286 sMessage.append(" eError: ");
287 sMessage.append(toOString(comphelper::anyToString( css::uno::Any(specialized.eError) )));
291 css::ucb::MissingPropertiesException specialized;
292 if ( caught >>= specialized )
294 sMessage.append(" Properties: ");
295 sMessage.append(toOString(comphelper::anyToString( css::uno::Any(specialized.Properties) )));
299 css::ucb::NameClashException specialized;
300 if ( caught >>= specialized )
302 sMessage.append(" Name: ");
303 sMessage.append(toOString( specialized.Name ));
307 css::util::MalformedNumberFormatException specialized;
308 if ( caught >>= specialized )
310 sMessage.append(" CheckPos: ");
311 sMessage.append( specialized.CheckPos );
315 css::xml::dom::DOMException specialized;
316 if ( caught >>= specialized )
318 sMessage.append(" Code: ");
319 sMessage.append(toOString(comphelper::anyToString( css::uno::Any(specialized.Code) )));
323 css::xml::dom::DOMException specialized;
324 if ( caught >>= specialized )
326 sMessage.append(" Code: ");
327 sMessage.append(toOString(comphelper::anyToString( css::uno::Any(specialized.Code) )));
331 css::xml::sax::SAXException specialized;
332 if ( caught >>= specialized )
334 sMessage.append("\n wrapped: ");
335 sMessage.append(exceptionToString( specialized.WrappedException ));
339 css::xml::sax::SAXParseException specialized;
340 if ( caught >>= specialized )
342 sMessage.append(" PublicId: ");
343 sMessage.append(toOString( specialized.PublicId ));
344 sMessage.append(" SystemId: ");
345 sMessage.append(toOString( specialized.SystemId ));
346 sMessage.append(" LineNumber: ");
347 sMessage.append( specialized.LineNumber );
348 sMessage.append(" ColumnNumber: ");
349 sMessage.append( specialized.ColumnNumber );
353 css::ucb::InteractiveIOException specialized;
354 if ( caught >>= specialized )
356 sMessage.append(" Code: ");
357 sMessage.append( static_cast<sal_Int32>(specialized.Code) );
362 OString exceptionToString(const css::uno::Any & caught)
364 OStringBuffer sMessage(512);
365 exceptionToStringImpl(sMessage, caught);
366 return sMessage.makeStringAndClear();
369 void DbgUnhandledException(const css::uno::Any & caught, const char* currentFunction, const char* fileAndLineNo,
370 const char* area, const char* explanatory)
372 OStringBuffer sMessage( 512 );
373 sMessage.append( OString::Concat("DBG_UNHANDLED_EXCEPTION in ") + currentFunction);
374 if (explanatory)
376 sMessage.append(OString::Concat("\n when: ") + explanatory);
378 sMessage.append(" exception: ");
379 exceptionToStringImpl(sMessage, caught);
381 if (area == nullptr)
382 area = "legacy.osl";
384 SAL_DETAIL_LOG_FORMAT(
385 SAL_DETAIL_ENABLE_LOG_WARN, SAL_DETAIL_LOG_LEVEL_WARN,
386 area, fileAndLineNo, "%s", sMessage.getStr());
389 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */