1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "exception.h"
44 \defgroup CoreExceptions
47 \class QmlDesigner::Exception
48 \ingroup CoreExceptions
49 \brief This is the abstract base class for all excetions.
50 Exceptions should be used in cases there is no other way to say something goes wrong. For example
51 the result would be a inconsistent model or a crash.
55 namespace QmlDesigner {
58 const char* demangle(const char* name)
64 res = abi::__cxa_demangle(name,
71 const char* demangle(const char* name)
78 bool Exception::s_shouldAssert = false;
80 void Exception::setShouldAssert(bool assert)
82 s_shouldAssert = assert;
85 bool Exception::shouldAssert()
87 return s_shouldAssert;
93 \param line use the __LINE__ macro
94 \param function use the __FUNCTION__ or the Q_FUNC_INFO macro
95 \param file use the __FILE__ macro
97 Exception::Exception(int line,
98 const QString &function,
101 m_function(function),
106 int nSize = backtrace(array, 50);
107 char ** symbols = backtrace_symbols(array, nSize);
109 for (int i = 0; i < nSize; i++)
111 m_backTrace.append(QString("%1\n").arg(symbols[i]));
118 Q_ASSERT_X(false, function.toLatin1(), QString("%1:%2 - %3").arg(file).arg(line).arg(function).toLatin1());
121 Exception::~Exception()
126 \brief Returns the unmangled backtrace of this exception
128 \returns the backtrace as a string
130 QString Exception::backTrace() const
136 \brief Returns the optional description of this exception
138 \returns the description as string
140 QString Exception::description() const
142 return QString("file: %1, function: %2, line: %3").arg(m_file, m_function, QString::number(m_line));
146 \brief Returns the line number where this exception was thrown
148 \returns the line number as integer
150 int Exception::line() const
156 \brief Returns the function name where this exception was thrown
158 \returns the function name as string
160 QString Exception::function() const
166 \brief Returns the file name where this exception was thrown
168 \returns the file name as string
170 QString Exception::file() const
175 QDebug operator<<(QDebug debug, const Exception &exception)
177 debug.nospace() << "Exception: " << exception.type() << "\n"
178 "Function: " << exception.function() << "\n"
179 "File: " << exception.file() << "\n"
180 "Line: " << exception.line() << "\n";
181 if (!exception.description().isEmpty())
182 debug.nospace() << exception.description();
184 if (!exception.backTrace().isEmpty())
185 debug.nospace() << exception.backTrace();
187 return debug.space();
191 \fn QString Exception::type() const
192 \brief Returns the type of this exception
194 \returns the type as a string