1 /*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 /*******************************************************************************
21 * Includes
22 ******************************************************************************/
23 #include "exceptions.h"
24
25 #include "debug.h"
26 #include "fileio/filepath.h"
27
28 #include <QtCore>
29
30 /*******************************************************************************
31 * Namespace
32 ******************************************************************************/
33 namespace librepcb {
34
35 /*******************************************************************************
36 * Class Exception
37 ******************************************************************************/
38
Exception(const char * file,int line,const QString & msg)39 Exception::Exception(const char* file, int line, const QString& msg) noexcept
40 : mMsg(msg), mFile(file), mLine(line) {
41 // print out the exception to the console/log output
42 Debug::instance()->print(Debug::DebugLevel_t::Exception, mMsg, file, line);
43 }
44
Exception(const Exception & other)45 Exception::Exception(const Exception& other) noexcept
46 : mMsg(other.mMsg), mFile(other.mFile), mLine(other.mLine) {
47 }
48
what() const49 const char* Exception::what() const noexcept {
50 if (mMsgUtf8.isNull()) {
51 mMsgUtf8 = mMsg.toUtf8();
52 }
53 return mMsgUtf8.constData();
54 }
55
56 /*******************************************************************************
57 * Class LogicError
58 ******************************************************************************/
59
LogicError(const char * file,int line,const QString & msg)60 LogicError::LogicError(const char* file, int line, const QString& msg) noexcept
61 : Exception(file, line, msg) {
62 }
63
LogicError(const LogicError & other)64 LogicError::LogicError(const LogicError& other) noexcept : Exception(other) {
65 }
66
67 /*******************************************************************************
68 * Class RuntimeError
69 ******************************************************************************/
70
RuntimeError(const char * file,int line,const QString & msg)71 RuntimeError::RuntimeError(const char* file, int line,
72 const QString& msg) noexcept
73 : Exception(file, line, msg) {
74 }
75
RuntimeError(const RuntimeError & other)76 RuntimeError::RuntimeError(const RuntimeError& other) noexcept
77 : Exception(other) {
78 }
79
80 /*******************************************************************************
81 * Class RangeError
82 ******************************************************************************/
83
RangeError(const char * file,int line,const QString & msg)84 RangeError::RangeError(const char* file, int line, const QString& msg) noexcept
85 : RuntimeError(file, line, msg) {
86 }
87
RangeError(const RangeError & other)88 RangeError::RangeError(const RangeError& other) noexcept : RuntimeError(other) {
89 }
90
91 /*******************************************************************************
92 * Class FileParseError
93 ******************************************************************************/
94
FileParseError(const char * file,int line,const FilePath & filePath,int fileLine,int fileColumn,const QString & invalidFileContent,const QString & msg)95 FileParseError::FileParseError(const char* file, int line,
96 const FilePath& filePath, int fileLine,
97 int fileColumn,
98 const QString& invalidFileContent,
99 const QString& msg) noexcept
100 : RuntimeError(file, line,
101 QString("File parse error: %1\n\nFile: %2\nLine,Column: "
102 "%3,%4\nInvalid Content: \"%5\"")
103 .arg(msg)
104 .arg(filePath.toNative())
105 .arg(fileLine)
106 .arg(fileColumn)
107 .arg(invalidFileContent)) {
108 }
109
FileParseError(const FileParseError & other)110 FileParseError::FileParseError(const FileParseError& other) noexcept
111 : RuntimeError(other) {
112 }
113
114 /*******************************************************************************
115 * Class UserCanceled
116 ******************************************************************************/
117
UserCanceled(const char * file,int line,const QString & msg)118 UserCanceled::UserCanceled(const char* file, int line,
119 const QString& msg) noexcept
120 : Exception(file, line, msg) {
121 }
122
UserCanceled(const UserCanceled & other)123 UserCanceled::UserCanceled(const UserCanceled& other) noexcept
124 : Exception(other) {
125 }
126
127 /*******************************************************************************
128 * End of File
129 ******************************************************************************/
130
131 } // namespace librepcb
132