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 <kicommon.h>
29#include <wx/string.h>
30
31
39#define THROW_IO_ERROR( msg ) throw IO_ERROR( msg, __FILE__, __FUNCTION__, __LINE__ )
40
45class KICOMMON_API KI_PARAM_ERROR // similar to std::invalid_argument for instance
46{
47public:
51 KI_PARAM_ERROR( const wxString& aMessage )
52 {
53 m_message = aMessage;
54 }
55
57
58 const wxString What() const
59 {
60 return m_message;
61 }
62
63 virtual ~KI_PARAM_ERROR() throw () {}
64
65private:
66 wxString m_message;
67};
68
69
76class KICOMMON_API IO_ERROR // : std::exception
77{
78public:
88 IO_ERROR( const wxString& aProblem, const char* aThrowersFile,
89 const char* aThrowersFunction, int aThrowersLineNumber )
90 {
91 init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber );
92 }
93
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 wxString What() const;
103
104 virtual ~IO_ERROR() throw () {}
105
106protected:
107 wxString problem;
108 wxString where;
109};
110
111
120{
123
128 std::string inputLine;
129
134 PARSE_ERROR( const wxString& aProblem, const char* aThrowersFile,
135 const char* aThrowersFunction, int aThrowersLineNumber,
136 const wxString& aSource, const char* aInputLine,
137 int aLineNumber, int aByteIndex ) :
138 IO_ERROR()
139 {
140 init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber,
141 aSource, aInputLine, aLineNumber, aByteIndex );
142 }
143
144 void init( const wxString& aProblem, const char* aThrowersFile,
145 const char* aThrowersFunction, int aThrowersLineNumber,
146 const wxString& aSource, const char* aInputLine,
147 int aLineNumber, int aByteIndex );
148
149 ~PARSE_ERROR() throw () {}
150
151 const wxString ParseProblem() { return parseProblem; }
152
153protected:
155 IO_ERROR(),
156 lineNumber( 0 ),
157 byteIndex( 0 )
158 {}
159
160protected:
161 wxString parseProblem;
162};
163
164
165#define THROW_PARSE_ERROR( aProblem, aSource, aInputLine, aLineNumber, aByteIndex ) \
166 throw PARSE_ERROR( aProblem, __FILE__, __FUNCTION__, __LINE__, aSource, aInputLine, \
167 aLineNumber, aByteIndex )
168
169
176{
179
180 FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion,
181 const wxString& aRequiredGenerator = wxEmptyString );
182 FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError, const wxString& aRequiredVersion,
183 const wxString& aRequiredGenerator = wxEmptyString );
185
186 void init( const wxString& aRequiredVersion,
187 const wxString& aRequiredGenerator = wxEmptyString );
188};
189
192#endif // KI_EXCEPTION_H_
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
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:88
wxString problem
Definition: ki_exception.h:107
wxString where
Definition: ki_exception.h:108
virtual ~IO_ERROR()
Definition: ki_exception.h:104
Hold a translatable error message and may be used when throwing exceptions containing a translated er...
Definition: ki_exception.h:46
KI_PARAM_ERROR(const wxString &aMessage)
Constructor.
Definition: ki_exception.h:51
const wxString What() const
Definition: ki_exception.h:58
virtual ~KI_PARAM_ERROR()
Definition: ki_exception.h:63
wxString m_message
Definition: ki_exception.h:66
#define KICOMMON_API
Definition: kicommon.h:28
Variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generate...
Definition: ki_exception.h:176
wxString requiredGenerator
Version of KiCad required to open file.
Definition: ki_exception.h:178
wxString requiredVersion
Date of KiCad file format required to open file.
Definition: ki_exception.h:177
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:120
int lineNumber
at which line number, 1 based index.
Definition: ki_exception.h:121
const wxString ParseProblem()
Definition: ki_exception.h:151
wxString parseProblem
Definition: ki_exception.h:161
std::string inputLine
problem line of input [say, from a LINE_READER].
Definition: ki_exception.h:128
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:134
int byteIndex
at which byte offset within the line, 1 based index
Definition: ki_exception.h:122