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{
99 requiredVersion = aRequiredVersion;
100
101 problem.Printf( _( "KiCad was unable to open this file because it was created with a more "
102 "recent version than the one you are running.\n\n"
103 "To open it you will need to upgrade KiCad to a version dated %s or "
104 "later." ),
105 aRequiredVersion );
106}
107
108
109FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion ) :
111{
112 init( aRequiredVersion );
113
114 lineNumber = 0;
115 byteIndex = 0;
116}
117
118
120 const wxString& aRequiredVersion ) :
122{
123 if( const FUTURE_FORMAT_ERROR* ffe = dynamic_cast<const FUTURE_FORMAT_ERROR*>( &aParseError ) )
124 {
125 requiredVersion = ffe->requiredVersion;
126 problem = ffe->Problem();
127 }
128 else
129 {
130 init( aRequiredVersion );
131
132 if( !aParseError.Problem().IsEmpty() )
133 problem += wxS( "\n\n" ) + _( "Full error text:" ) + wxS( "\n" ) + aParseError.Problem();
134 }
135
136 lineNumber = aParseError.lineNumber;
137 byteIndex = aParseError.byteIndex;
138 inputLine = aParseError.inputLine;
139}
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:106
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
wxString where
Definition: ki_exception.h:107
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:175
FUTURE_FORMAT_ERROR(const wxString &aRequiredVersion)
Definition: exceptions.cpp:109
wxString requiredVersion
version or date of KiCad required to open file
Definition: ki_exception.h:176
void init(const wxString &aRequiredVersion)
Definition: exceptions.cpp:97
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:119
int lineNumber
at which line number, 1 based index.
Definition: ki_exception.h:120
wxString parseProblem
Definition: ki_exception.h:160
std::string inputLine
problem line of input [say, from a LINE_READER].
Definition: ki_exception.h:127
int byteIndex
at which byte offset within the line, 1 based index
Definition: ki_exception.h:121
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