aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/designercore/include/exception.h
blob: a6337277e9142cea05a41b327ec318a901de93d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include <qmldesignercorelib_global.h>

#include <QString>
#include <QDebug>

namespace QmlDesigner {

class QMLDESIGNERCORE_EXPORT Exception
{
public:
    Exception(int line,
              const QByteArray &function,
              const QByteArray &file);
    virtual ~Exception();

    virtual QString type() const = 0;
    QString description() const;
    void showException(const QString &title = QString()) const;
    static void setShowExceptionCallback(
        std::function<void(QStringView title, QStringView description)> callback);

    int line() const;
    QString function() const;
    QString file() const;
    QString backTrace() const;

    void createWarning() const;

    static void setShouldAssert(bool assert);
    static bool shouldAssert();
    static void setWarnAboutException(bool warn);
    static bool warnAboutException();

protected:
    Exception(int line,
              const QByteArray &function,
              const QByteArray &file,
              const QString &description);
    static QString defaultDescription(int line, const QByteArray &function, const QByteArray &file);
    QString defaultDescription();

private:
    const int m_line;
    const QString m_function;
    const QString m_file;
    const QString m_description;
    const QString m_backTrace;
    static bool s_shouldAssert;
    static bool s_warnAboutException;
};

QMLDESIGNERCORE_EXPORT QDebug operator<<(QDebug debug, const Exception &exception);

}