KiCad PCB EDA Suite
exceptions.cpp
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) 2017 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 #include <wx/wx.h>
26 #include <ki_exception.h>
27 
28 
29 const wxString IO_ERROR::What() const
30 {
31 #ifdef DEBUG
32  return wxString( "IO_ERROR: " ) + Problem() + "\n\n" + Where();
33 #else
34  return Problem();
35 #endif
36 }
37 
38 
39 const wxString IO_ERROR::Where() const
40 {
41  return where;
42 }
43 
44 
45 const wxString IO_ERROR::Problem() const
46 {
47  return problem;
48 }
49 
50 
51 
52 void IO_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
53  const char* aThrowersFunction, int aThrowersLineNumber )
54 {
55  problem = aProblem;
56 
57  // The throwers filename is a full filename, depending on Kicad source location.
58  // a short filename will be printed (it is better for user, the full filename has no meaning).
59  wxString srcname = aThrowersFile;
60 
61  where.Printf( _( "from %s : %s() line:%d" ),
62  srcname.AfterLast( '/' ),
63  wxString( aThrowersFunction ),
64  aThrowersLineNumber );
65 }
66 
67 
68 void PARSE_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
69  const char* aThrowersFunction, int aThrowersLineNumber,
70  const wxString& aSource, const char* aInputLine, int aLineNumber,
71  int aByteIndex )
72 {
73  problem.Printf( _( "%s in \"%s\", line %d, offset %d" ),
74  aProblem,
75  aSource,
76  aLineNumber,
77  aByteIndex );
78 
79  inputLine = aInputLine;
80  lineNumber = aLineNumber;
81  byteIndex = aByteIndex;
82 
83  // The throwers filename is a full filename, depending on Kicad source location.
84  // a short filename will be printed (it is better for user, the full filename has no meaning).
85  wxString srcname = aThrowersFile;
86 
87  where.Printf( _( "from %s : %s() line:%d" ),
88  srcname.AfterLast( '/' ),
89  wxString( aThrowersFunction ),
90  aThrowersLineNumber );
91 }
92 
93 
95  const wxString& aRequiredVersion ) :
96  PARSE_ERROR(), requiredVersion( aRequiredVersion )
97 {
98  // Avoid double-printing the error message
99  bool wrapped_same_type = !!( dynamic_cast<const FUTURE_FORMAT_ERROR *>( &aParseError ) );
100 
101  if( wrapped_same_type )
102  {
103  problem = aParseError.Problem();
104  }
105  else
106  {
107  problem.Printf( _( "KiCad was unable to open this file, as it was created with a more\n"
108  "recent version than the one you are running.\n"
109  "To open it you will need to upgrade KiCad to a more recent version.\n\n"
110  "Date of KiCad version required (or newer): %s\n\n"
111  "Full error text:\n%s" ),
112  requiredVersion, aParseError.Problem() );
113  }
114 
115  lineNumber = aParseError.lineNumber;
116  byteIndex = aParseError.byteIndex;
117  inputLine = aParseError.inputLine;
118 }
void init(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber)
Definition: exceptions.cpp:52
FUTURE_FORMAT_ERROR(const PARSE_ERROR &aParseError, const wxString &aRequiredVersion)
Definition: exceptions.cpp:94
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:45
virtual const wxString Where() const
where did the Problem() occur?
Definition: exceptions.cpp:39
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
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:68
int lineNumber
at which line number, 1 based index.
Definition: ki_exception.h:125
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,...
Definition: ki_exception.h:123
#define _(s)
Definition: 3d_actions.cpp:33
int byteIndex
at which byte offset within the line, 1 based index
Definition: ki_exception.h:126
wxString where
Definition: ki_exception.h:112
std::string inputLine
problem line of input [say, from a LINE_READER].
Definition: ki_exception.h:132
wxString problem
Definition: ki_exception.h:111