KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <[email protected]>
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/string.h>
26#include <wx/translation.h>
27#include <ki_exception.h>
28
29
30const wxString IO_ERROR::What() const
31{
32#ifdef DEBUG
33 return wxString( wxS( "IO_ERROR: " ) ) + Problem() + wxS("\n\n" ) + Where();
34#else
35 return Problem();
36#endif
37}
38
39
40const wxString IO_ERROR::Where() const
41{
42 return where;
43}
44
45
46const wxString IO_ERROR::Problem() const
47{
48 return problem;
49}
50
51
52
53void IO_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
54 const char* aThrowersFunction, int aThrowersLineNumber )
55{
56 problem = aProblem;
57
58 // The throwers filename is a full filename, depending on Kicad source location.
59 // a short filename will be printed (it is better for user, the full filename has no meaning).
60 wxString srcname = aThrowersFile;
61
62 // No need for translations of source code file/line messages (and wxWidget's translation
63 // stuff has bitten us before. May be related to KICAD-YP.
64 where.Printf( wxS( "from %s : %s() line %d" ),
65 srcname.AfterLast( '/' ),
66 wxString( aThrowersFunction ),
67 aThrowersLineNumber );
68}
69
70
71void PARSE_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
72 const char* aThrowersFunction, int aThrowersLineNumber,
73 const wxString& aSource, const char* aInputLine, int aLineNumber,
74 int aByteIndex )
75{
76 parseProblem = aProblem;
77
78 problem.Printf( _( "%s in '%s', line %d, offset %d." ),
79 aProblem,
80 aSource,
81 aLineNumber,
82 aByteIndex );
83
84 inputLine = aInputLine;
85 lineNumber = aLineNumber;
86 byteIndex = aByteIndex;
87
88 // The throwers filename is a full filename, depending on Kicad source location.
89 // a short filename will be printed (it is better for user, the full filename has no meaning).
90 wxString srcname = aThrowersFile;
91
92 // No need for translations of source code file/line messages (and wxWidget's translation
93 // stuff has bitten us before. May be related to KICAD-YP.
94 where.Printf( wxS( "from %s : %s() line %d" ),
95 srcname.AfterLast( '/' ),
96 wxString( aThrowersFunction ),
97 aThrowersLineNumber );
98}
99
100
101void FUTURE_FORMAT_ERROR::init( const wxString& aRequiredVersion,
102 const wxString& aRequiredGenerator )
103{
104 requiredVersion = aRequiredVersion;
105 requiredGenerator = aRequiredGenerator;
106
107 if( requiredGenerator.IsEmpty() )
108 {
109 problem.Printf( _( "KiCad was unable to open this file because it was created with a more "
110 "recent version than the one you are running.\n\n"
111 "To open it you will need to upgrade KiCad to a version dated %s or "
112 "later." ),
113 aRequiredVersion );
114 }
115 else
116 {
117 problem.Printf( _( "KiCad was unable to open this file because it was created with a more "
118 "recent version than the one you are running.\n\n"
119 "To open it you will need to upgrade KiCad to version %s or "
120 "later (file format dated %s or later)." ),
121 aRequiredGenerator, aRequiredVersion );
122 }
123}
124
125
126FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion,
127 const wxString& aRequiredGenerator ) :
129{
130 init( aRequiredVersion, aRequiredGenerator );
131
132 lineNumber = 0;
133 byteIndex = 0;
134}
135
136
138 const wxString& aRequiredVersion,
139 const wxString& aRequiredGenerator ) :
141{
142 if( const FUTURE_FORMAT_ERROR* ffe = dynamic_cast<const FUTURE_FORMAT_ERROR*>( &aParseError ) )
143 {
144 requiredVersion = ffe->requiredVersion;
145 requiredGenerator = ffe->requiredGenerator;
146 problem = ffe->Problem();
147 }
148 else
149 {
150 init( aRequiredVersion, aRequiredGenerator );
151
152 if( !aParseError.Problem().IsEmpty() )
153 problem += wxS( "\n\n" ) + _( "Full error text:" ) + wxS( "\n" ) + aParseError.Problem();
154 }
155
156 lineNumber = aParseError.lineNumber;
157 byteIndex = aParseError.byteIndex;
158 inputLine = aParseError.inputLine;
159}
void init(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber)
Definition: exceptions.cpp:53
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
wxString problem
Definition: ki_exception.h:107
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
wxString where
Definition: ki_exception.h:108
virtual const wxString Where() const
where did the Problem() occur?
Definition: exceptions.cpp:40
#define _(s)
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
FUTURE_FORMAT_ERROR(const wxString &aRequiredVersion, const wxString &aRequiredGenerator=wxEmptyString)
Definition: exceptions.cpp:126
void init(const wxString &aRequiredVersion, const wxString &aRequiredGenerator=wxEmptyString)
Definition: exceptions.cpp:101
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
wxString parseProblem
Definition: ki_exception.h:161
std::string inputLine
problem line of input [say, from a LINE_READER].
Definition: ki_exception.h:128
int byteIndex
at which byte offset within the line, 1 based index
Definition: ki_exception.h:122
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:71