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 
40 
47 class IO_ERROR // : std::exception
48 {
49 public:
63  IO_ERROR( const wxString& aProblem, const char* aThrowersFile,
64  const char* aThrowersFunction, int aThrowersLineNumber )
65  {
66  init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber );
67  }
68 
69  IO_ERROR() {}
70 
71  void init( const wxString& aProblem, const char* aThrowersFile,
72  const char* aThrowersFunction, int aThrowersLineNumber );
73 
74  virtual const wxString Problem() const;
75  virtual const wxString Where() const;
76 
77  virtual const wxString What() const;
78 
79  virtual ~IO_ERROR() throw () {}
80 
81 protected:
82  wxString problem;
83  wxString where;
84 };
85 
86 
94 struct PARSE_ERROR : public IO_ERROR
95 {
96  int lineNumber;
97  int byteIndex;
98 
103  std::string inputLine;
104 
110  PARSE_ERROR( const wxString& aProblem, const char* aThrowersFile,
111  const char* aThrowersFunction, int aThrowersLineNumber,
112  const wxString& aSource,
113  const char* aInputLine,
114  int aLineNumber, int aByteIndex ) :
115  IO_ERROR()
116  {
117  init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber,
118  aSource, aInputLine, aLineNumber, aByteIndex );
119  }
120 
121  void init( const wxString& aProblem, const char* aThrowersFile,
122  const char* aThrowersFunction, int aThrowersLineNumber,
123  const wxString& aSource, const char* aInputLine,
124  int aLineNumber, int aByteIndex );
125 
126  ~PARSE_ERROR() throw () {}
127 
128 protected:
129  PARSE_ERROR(): IO_ERROR(), lineNumber( 0 ), byteIndex( 0 ) {}
130 };
131 
132 
133 #define THROW_PARSE_ERROR( aProblem, aSource, aInputLine, aLineNumber, aByteIndex ) \
134  throw PARSE_ERROR( aProblem, __FILE__, __FUNCTION__, __LINE__, aSource, aInputLine, aLineNumber, aByteIndex )
135 
136 
144 {
145  wxString requiredVersion;
146 
147  FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError, const wxString& aRequiredVersion );
148  ~FUTURE_FORMAT_ERROR() throw () {}
149 };
150 
153 #endif // KI_EXCEPTION_H_
virtual const wxString Where() const
where did the Problem() occur?
Definition: exceptions.cpp:43
IO_ERROR(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber)
Constructor.
Definition: ki_exception.h:63
void init(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber)
Definition: exceptions.cpp:56
FUTURE_FORMAT_ERROR(const PARSE_ERROR &aParseError, const wxString &aRequiredVersion)
Definition: exceptions.cpp:90
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:49
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
int lineNumber
at which line number, 1 based index.
Definition: ki_exception.h:96
wxString requiredVersion
version or date of KiCad required to open file
Definition: ki_exception.h:145
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
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's report and his call site information: CPP source file, function, and line number.
Definition: ki_exception.h:94
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:110
int byteIndex
at which byte offset within the line, 1 based index
Definition: ki_exception.h:97
wxString where
Definition: ki_exception.h:83
Struct FUTURE_FORMAT_ERROR variant of PARSE_ERROR indicating that a syntax or related error was likel...
Definition: ki_exception.h:143
std::string inputLine
problem line of input [say, from a LINE_READER].
Definition: ki_exception.h:103
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
wxString problem
Definition: ki_exception.h:82
virtual ~IO_ERROR()
Definition: ki_exception.h:79