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#include <wx/string.h>
26
27
32
33
35#define THROW_IO_ERROR( msg ) throw IO_ERROR( msg, __FILE__, __FUNCTION__, __LINE__ )
36
41class KICOMMON_API KI_PARAM_ERROR // similar to std::invalid_argument for instance
42{
43public:
47 KI_PARAM_ERROR( const wxString& aMessage )
48 {
49 m_message = aMessage;
50 }
51
53
54 const wxString What() const
55 {
56 return m_message;
57 }
58
59 virtual ~KI_PARAM_ERROR() throw () {}
60
61private:
62 wxString m_message;
63};
64
65
72class KICOMMON_API IO_ERROR : public std::exception
73{
74public:
84 IO_ERROR( const wxString& aProblem, const char* aThrowersFile,
85 const char* aThrowersFunction, int aThrowersLineNumber )
86 {
87 init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber );
88 }
89
90 IO_ERROR() = default;
91 ~IO_ERROR() throw() {}
92
93 void init( const wxString& aProblem, const char* aThrowersFile,
94 const char* aThrowersFunction, int aThrowersLineNumber );
95
96 virtual const wxString Problem() const;
97 virtual const wxString Where() const;
98
99 virtual const char* what() const throw() override;
100 virtual const wxString What() const;
101
102protected:
103 wxString problem;
104 wxString where;
105};
106
107
116{
119
124 std::string inputLine;
125
130 PARSE_ERROR( const wxString& aProblem, const char* aThrowersFile,
131 const char* aThrowersFunction, int aThrowersLineNumber,
132 const wxString& aSource, const char* aInputLine,
133 int aLineNumber, int aByteIndex ) :
134 IO_ERROR()
135 {
136 init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber,
137 aSource, aInputLine, aLineNumber, aByteIndex );
138 }
139
140 void init( const wxString& aProblem, const char* aThrowersFile,
141 const char* aThrowersFunction, int aThrowersLineNumber,
142 const wxString& aSource, const char* aInputLine,
143 int aLineNumber, int aByteIndex );
144
145 ~PARSE_ERROR() throw () {}
146
147 const wxString ParseProblem() { return parseProblem; }
148
149protected:
151 IO_ERROR(),
152 lineNumber( 0 ),
153 byteIndex( 0 )
154 {}
155
156protected:
157 wxString parseProblem;
158};
159
160
161#define THROW_PARSE_ERROR( aProblem, aSource, aInputLine, aLineNumber, aByteIndex ) \
162 throw PARSE_ERROR( aProblem, __FILE__, __FUNCTION__, __LINE__, aSource, aInputLine, \
163 aLineNumber, aByteIndex )
164
165
172{
175
176 FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion,
177 const wxString& aRequiredGenerator = wxEmptyString );
178 FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError, const wxString& aRequiredVersion,
179 const wxString& aRequiredGenerator = wxEmptyString );
181
182 void init( const wxString& aRequiredVersion,
183 const wxString& aRequiredGenerator = wxEmptyString );
184};
185
187
188#endif // KI_EXCEPTION_H_
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)