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