KiCad PCB EDA Suite
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 <dick@softplc.com>
5  * Copyright (C) 2016 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 
37 #define THROW_IO_ERROR( msg ) throw IO_ERROR( msg, __FILE__, __FUNCTION__, __LINE__ )
39 
45 class KI_PARAM_ERROR // similar to std::invalid_argument for instance
46 {
47 public:
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 
65 private:
66  wxString m_message;
67 };
68 
69 
76 class IO_ERROR // : std::exception
77 {
78 public:
92  IO_ERROR( const wxString& aProblem, const char* aThrowersFile,
93  const char* aThrowersFunction, int aThrowersLineNumber )
94  {
95  init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber );
96  }
97 
98  IO_ERROR() {}
99 
100  void init( const wxString& aProblem, const char* aThrowersFile,
101  const char* aThrowersFunction, int aThrowersLineNumber );
102 
103  virtual const wxString Problem() const;
104  virtual const wxString Where() const;
105 
106  virtual const wxString What() const;
107 
108  virtual ~IO_ERROR() throw () {}
109 
110 protected:
111  wxString problem;
112  wxString where;
113 };
114 
115 
123 struct PARSE_ERROR : public IO_ERROR
124 {
126  int byteIndex;
127 
132  std::string inputLine;
133 
139  PARSE_ERROR( const wxString& aProblem, const char* aThrowersFile,
140  const char* aThrowersFunction, int aThrowersLineNumber,
141  const wxString& aSource,
142  const char* aInputLine,
143  int aLineNumber, int aByteIndex ) :
144  IO_ERROR()
145  {
146  init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber,
147  aSource, aInputLine, aLineNumber, aByteIndex );
148  }
149 
150  void init( const wxString& aProblem, const char* aThrowersFile,
151  const char* aThrowersFunction, int aThrowersLineNumber,
152  const wxString& aSource, const char* aInputLine,
153  int aLineNumber, int aByteIndex );
154 
155  ~PARSE_ERROR() throw () {}
156 
157 protected:
158  PARSE_ERROR(): IO_ERROR(), lineNumber( 0 ), byteIndex( 0 ) {}
159 };
160 
161 
162 #define THROW_PARSE_ERROR( aProblem, aSource, aInputLine, aLineNumber, aByteIndex ) \
163  throw PARSE_ERROR( aProblem, __FILE__, __FUNCTION__, __LINE__, aSource, aInputLine, aLineNumber, aByteIndex )
164 
165 
173 {
174  wxString requiredVersion;
175 
176  FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError, const wxString& aRequiredVersion );
177  ~FUTURE_FORMAT_ERROR() throw () {}
178 };
179 
182 #endif // KI_EXCEPTION_H_
IO_ERROR(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber)
Constructor.
Definition: ki_exception.h:92
virtual ~KI_PARAM_ERROR()
Definition: ki_exception.h:63
KI_PARAM_ERROR(const wxString &aMessage)
Constructor.
Definition: ki_exception.h:51
int lineNumber
at which line number, 1 based index.
Definition: ki_exception.h:125
const wxString What() const
Definition: ki_exception.h:58
wxString m_message
Definition: ki_exception.h:66
wxString requiredVersion
version or date of KiCad required to open file
Definition: ki_exception.h:174
Struct PARSE_ERROR contains a filename or source description, a problem input line, a line number, a byte offset, and an error message which contains the the caller&#39;s report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:123
PARSE_ERROR(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber, const wxString &aSource, const char *aInputLine, int aLineNumber, int aByteIndex)
Constructor which is normally called via the macro THROW_PARSE_ERROR so that FILE and FUNCTION and LI...
Definition: ki_exception.h:139
int byteIndex
at which byte offset within the line, 1 based index
Definition: ki_exception.h:126
wxString where
Definition: ki_exception.h:112
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:172
std::string inputLine
problem line of input [say, from a LINE_READER].
Definition: ki_exception.h:132
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76
wxString problem
Definition: ki_exception.h:111
virtual ~IO_ERROR()
Definition: ki_exception.h:108
class KI_PARAM_ERROR is a class used to hold a translatable error message and may be used when throwi...
Definition: ki_exception.h:45