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 where.Printf( _( "from %s : %s() line %d" ),
63 srcname.AfterLast( '/' ),
64 wxString( aThrowersFunction ),
65 aThrowersLineNumber );
66}
67
68
69void PARSE_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
70 const char* aThrowersFunction, int aThrowersLineNumber,
71 const wxString& aSource, const char* aInputLine, int aLineNumber,
72 int aByteIndex )
73{
74 parseProblem = aProblem;
75
76 problem.Printf( _( "%s in '%s', line %d, offset %d." ),
77 aProblem,
78 aSource,
79 aLineNumber,
80 aByteIndex );
81
82 inputLine = aInputLine;
83 lineNumber = aLineNumber;
84 byteIndex = aByteIndex;
85
86 // The throwers filename is a full filename, depending on Kicad source location.
87 // a short filename will be printed (it is better for user, the full filename has no meaning).
88 wxString srcname = aThrowersFile;
89
90 where.Printf( _( "from %s : %s() line:%d" ),
91 srcname.AfterLast( '/' ),
92 wxString( aThrowersFunction ),
93 aThrowersLineNumber );
94}
95
96
97void FUTURE_FORMAT_ERROR::init( const wxString& aRequiredVersion,
98 const wxString& aRequiredGenerator )
99{
100 requiredVersion = aRequiredVersion;
101 requiredGenerator = aRequiredGenerator;
102
103 if( requiredGenerator.IsEmpty() )
104 {
105 problem.Printf( _( "KiCad was unable to open this file because it was created with a more "
106 "recent version than the one you are running.\n\n"
107 "To open it you will need to upgrade KiCad to a version dated %s or "
108 "later." ),
109 aRequiredVersion );
110 }
111 else
112 {
113 problem.Printf( _( "KiCad was unable to open this file because it was created with a more "
114 "recent version than the one you are running.\n\n"
115 "To open it you will need to upgrade KiCad to version %s or "
116 "later (file format dated %s or later)." ),
117 aRequiredGenerator, aRequiredVersion );
118 }
119}
120
121
122FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion,
123 const wxString& aRequiredGenerator ) :
125{
126 init( aRequiredVersion, aRequiredGenerator );
127
128 lineNumber = 0;
129 byteIndex = 0;
130}
131
132
134 const wxString& aRequiredVersion,
135 const wxString& aRequiredGenerator ) :
137{
138 if( const FUTURE_FORMAT_ERROR* ffe = dynamic_cast<const FUTURE_FORMAT_ERROR*>( &aParseError ) )
139 {
140 requiredVersion = ffe->requiredVersion;
141 requiredGenerator = ffe->requiredGenerator;
142 problem = ffe->Problem();
143 }
144 else
145 {
146 init( aRequiredVersion, aRequiredGenerator );
147
148 if( !aParseError.Problem().IsEmpty() )
149 problem += wxS( "\n\n" ) + _( "Full error text:" ) + wxS( "\n" ) + aParseError.Problem();
150 }
151
152 lineNumber = aParseError.lineNumber;
153 byteIndex = aParseError.byteIndex;
154 inputLine = aParseError.inputLine;
155}
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:122
void init(const wxString &aRequiredVersion, const wxString &aRequiredGenerator=wxEmptyString)
Definition: exceptions.cpp:97
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:69