KiCad PCB EDA Suite
Loading...
Searching...
No Matches
ki_exception.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2007-2016 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef KI_EXCEPTION_H_
26#define KI_EXCEPTION_H_
27
28#include <wx/string.h>
29
30
38#define THROW_IO_ERROR( msg ) throw IO_ERROR( msg, __FILE__, __FUNCTION__, __LINE__ )
39
44class KI_PARAM_ERROR // similar to std::invalid_argument for instance
45{
46public:
50 KI_PARAM_ERROR( const wxString& aMessage )
51 {
52 m_message = aMessage;
53 }
54
56
57 const wxString What() const
58 {
59 return m_message;
60 }
61
62 virtual ~KI_PARAM_ERROR() throw () {}
63
64private:
65 wxString m_message;
66};
67
68
75class IO_ERROR // : std::exception
76{
77public:
87 IO_ERROR( const wxString& aProblem, const char* aThrowersFile,
88 const char* aThrowersFunction, int aThrowersLineNumber )
89 {
90 init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber );
91 }
92
94
95 void init( const wxString& aProblem, const char* aThrowersFile,
96 const char* aThrowersFunction, int aThrowersLineNumber );
97
98 virtual const wxString Problem() const;
99 virtual const wxString Where() const;
100
101 virtual const wxString What() const;
102
103 virtual ~IO_ERROR() throw () {}
104
105protected:
106 wxString problem;
107 wxString where;
108};
109
110
118struct PARSE_ERROR : public IO_ERROR
119{
122
127 std::string inputLine;
128
133 PARSE_ERROR( const wxString& aProblem, const char* aThrowersFile,
134 const char* aThrowersFunction, int aThrowersLineNumber,
135 const wxString& aSource, const char* aInputLine,
136 int aLineNumber, int aByteIndex ) :
137 IO_ERROR()
138 {
139 init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber,
140 aSource, aInputLine, aLineNumber, aByteIndex );
141 }
142
143 void init( const wxString& aProblem, const char* aThrowersFile,
144 const char* aThrowersFunction, int aThrowersLineNumber,
145 const wxString& aSource, const char* aInputLine,
146 int aLineNumber, int aByteIndex );
147
148 ~PARSE_ERROR() throw () {}
149
150 const wxString ParseProblem() { return parseProblem; }
151
152protected:
154 IO_ERROR(),
155 lineNumber( 0 ),
156 byteIndex( 0 )
157 {}
158
159protected:
160 wxString parseProblem;
161};
162
163
164#define THROW_PARSE_ERROR( aProblem, aSource, aInputLine, aLineNumber, aByteIndex ) \
165 throw PARSE_ERROR( aProblem, __FILE__, __FUNCTION__, __LINE__, aSource, aInputLine, \
166 aLineNumber, aByteIndex )
167
168
175{
177
178 FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion );
179 FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError, const wxString& aRequiredVersion );
181
182 void init( const wxString& aRequiredVersion );
183};
184
187#endif // KI_EXCEPTION_H_
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
void init(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber)
Definition: exceptions.cpp:53
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
IO_ERROR(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber)
Use macro THROW_IO_ERROR() to wrap a call to this constructor at the call site.
Definition: ki_exception.h:87
wxString problem
Definition: ki_exception.h:106
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
wxString where
Definition: ki_exception.h:107
virtual ~IO_ERROR()
Definition: ki_exception.h:103
virtual const wxString Where() const
where did the Problem() occur?
Definition: exceptions.cpp:40
Hold a translatable error message and may be used when throwing exceptions containing a translated er...
Definition: ki_exception.h:45
KI_PARAM_ERROR(const wxString &aMessage)
Constructor.
Definition: ki_exception.h:50
const wxString What() const
Definition: ki_exception.h:57
virtual ~KI_PARAM_ERROR()
Definition: ki_exception.h:62
wxString m_message
Definition: ki_exception.h:65
Variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generate...
Definition: ki_exception.h:175
wxString requiredVersion
version or date of KiCad required to open file
Definition: ki_exception.h:176
void init(const wxString &aRequiredVersion)
Definition: exceptions.cpp:97
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:119
int lineNumber
at which line number, 1 based index.
Definition: ki_exception.h:120
const wxString ParseProblem()
Definition: ki_exception.h:150
wxString parseProblem
Definition: ki_exception.h:160
std::string inputLine
problem line of input [say, from a LINE_READER].
Definition: ki_exception.h:127
PARSE_ERROR(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber, const wxString &aSource, const char *aInputLine, int aLineNumber, int aByteIndex)
Normally called via the macro THROW_PARSE_ERROR so that FILE, FUNCTION, and LINE can be captured from...
Definition: ki_exception.h:133
int byteIndex
at which byte offset within the line, 1 based index
Definition: ki_exception.h:121
void init(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber, const wxString &aSource, const char *aInputLine, int aLineNumber, int aByteIndex)
Definition: exceptions.cpp:69