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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef KI_EXCEPTION_H_
22#define KI_EXCEPTION_H_
23
24#include <kicommon.h>
25
26#include <wx/string.h>
27
28
33
34
36#define THROW_IO_ERROR( msg ) throw IO_ERROR( msg, __FILE__, __FUNCTION__, __LINE__ )
37#define THROW_IO_ERRORF( msg, ... ) throw IO_ERROR( wxString::Format( msg, __VA_ARGS__ ), \
38 __FILE__, __FUNCTION__, __LINE__ )
39
44class KICOMMON_API 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 KICOMMON_API IO_ERROR : public 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
93 IO_ERROR() = default;
94 ~IO_ERROR() throw() {}
95
96 void init( const wxString& aProblem, const char* aThrowersFile,
97 const char* aThrowersFunction, int aThrowersLineNumber );
98
99 virtual const wxString Problem() const;
100 virtual const wxString Where() const;
101
102 virtual const char* what() const throw() override;
103 virtual const wxString What() const;
104
105protected:
106 wxString problem;
107 wxString where;
108};
109
110
117{
118public:
124 IO_CANCELLED( const char* aThrowersFile, const char* aThrowersFunction, int aThrowersLineNumber,
125 const wxString& aProblem = wxEmptyString );
126};
127
128
129#define THROW_IO_CANCELLED() throw IO_CANCELLED( __FILE__, __FUNCTION__, __LINE__ )
130
131#define THROW_IO_CANCELLED_MSG( msg ) throw IO_CANCELLED( __FILE__, __FUNCTION__, __LINE__, msg )
132
133
142{
145
150 std::string inputLine;
151
156 PARSE_ERROR( const wxString& aProblem, const char* aThrowersFile,
157 const char* aThrowersFunction, int aThrowersLineNumber,
158 const wxString& aSource, const char* aInputLine,
159 int aLineNumber, int aByteIndex ) :
160 IO_ERROR()
161 {
162 init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber,
163 aSource, aInputLine, aLineNumber, aByteIndex );
164 }
165
166 void init( const wxString& aProblem, const char* aThrowersFile,
167 const char* aThrowersFunction, int aThrowersLineNumber,
168 const wxString& aSource, const char* aInputLine,
169 int aLineNumber, int aByteIndex );
170
171 ~PARSE_ERROR() throw () {}
172
173 const wxString ParseProblem() { return parseProblem; }
174
175protected:
177 IO_ERROR(),
178 lineNumber( 0 ),
179 byteIndex( 0 )
180 {}
181
182protected:
183 wxString parseProblem;
184};
185
186
187#define THROW_PARSE_ERROR( aProblem, aSource, aInputLine, aLineNumber, aByteIndex ) \
188 throw PARSE_ERROR( aProblem, __FILE__, __FUNCTION__, __LINE__, aSource, aInputLine, \
189 aLineNumber, aByteIndex )
190
191
198{
201
202 FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion,
203 const wxString& aRequiredGenerator = wxEmptyString );
204 FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError, const wxString& aRequiredVersion,
205 const wxString& aRequiredGenerator = wxEmptyString );
207
208 void init( const wxString& aRequiredVersion,
209 const wxString& aRequiredGenerator = wxEmptyString );
210};
211
213
214#endif // KI_EXCEPTION_H_
IO_CANCELLED(const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber, const wxString &aProblem=wxEmptyString)
Normally thrown via the macro THROW_IO_CANCELLED(), which supplies the call-site file,...
void init(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber)
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.
wxString problem
wxString where
IO_ERROR()=default
KI_PARAM_ERROR(const wxString &aMessage)
Constructor.
const wxString What() const
virtual ~KI_PARAM_ERROR()
wxString m_message
#define KICOMMON_API
Definition kicommon.h:27
wxString requiredGenerator
Version of KiCad required to open file.
FUTURE_FORMAT_ERROR(const wxString &aRequiredVersion, const wxString &aRequiredGenerator=wxEmptyString)
wxString requiredVersion
Date of KiCad file format required to open file.
int lineNumber
at which line number, 1 based index.
const wxString ParseProblem()
wxString parseProblem
std::string inputLine
problem line of input [say, from a LINE_READER].
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...
int byteIndex
at which byte offset within the line, 1 based index
void init(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber, const wxString &aSource, const char *aInputLine, int aLineNumber, int aByteIndex)