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
72IO_CANCELLED::IO_CANCELLED( const char* aThrowersFile, const char* aThrowersFunction, int aThrowersLineNumber,
73 const wxString& aProblem ) :
74 IO_ERROR( aProblem.IsEmpty() ? _( "Canceled by user." ) : aProblem, aThrowersFile, aThrowersFunction,
75 aThrowersLineNumber )
76{
77}
78
79
80void PARSE_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
81 const char* aThrowersFunction, int aThrowersLineNumber,
82 const wxString& aSource, const char* aInputLine, int aLineNumber,
83 int aByteIndex )
84{
85 parseProblem = aProblem;
86
87 problem.Printf( _( "%s in '%s', line %d, offset %d." ),
88 aProblem,
89 aSource,
90 aLineNumber,
91 aByteIndex );
92
93 inputLine = aInputLine;
94 lineNumber = aLineNumber;
95 byteIndex = aByteIndex;
96
97 // The throwers filename is a full filename, depending on KiCad source location.
98 // a short filename will be printed (it is better for user, the full filename has no meaning).
99 wxString srcname = aThrowersFile;
100
101 // No need for translations of source code file/line messages (and wxWidget's translation
102 // stuff has bitten us before. May be related to KICAD-YP.
103 where.Printf( wxS( "from %s : %s() line %d" ),
104 srcname.AfterLast( '/' ),
105 wxString( aThrowersFunction ),
106 aThrowersLineNumber );
107}
108
109
110void FUTURE_FORMAT_ERROR::init( const wxString& aRequiredVersion,
111 const wxString& aRequiredGenerator )
112{
113 requiredVersion = aRequiredVersion;
114 requiredGenerator = aRequiredGenerator;
115
116 if( requiredGenerator.IsEmpty() )
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 a version dated %s or "
121 "later." ),
122 aRequiredVersion );
123 }
124 else
125 {
126 problem.Printf( _( "KiCad was unable to open this file because it was created with a more "
127 "recent version than the one you are running.\n\n"
128 "To open it you will need to upgrade KiCad to version %s or "
129 "later (file format dated %s or later)." ),
130 aRequiredGenerator, aRequiredVersion );
131 }
132}
133
134
135FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion,
136 const wxString& aRequiredGenerator ) :
138{
139 init( aRequiredVersion, aRequiredGenerator );
140
141 lineNumber = 0;
142 byteIndex = 0;
143}
144
145
147 const wxString& aRequiredVersion,
148 const wxString& aRequiredGenerator ) :
150{
151 if( const FUTURE_FORMAT_ERROR* ffe = dynamic_cast<const FUTURE_FORMAT_ERROR*>( &aParseError ) )
152 {
153 requiredVersion = ffe->requiredVersion;
154 requiredGenerator = ffe->requiredGenerator;
155 problem = ffe->Problem();
156 }
157 else
158 {
159 init( aRequiredVersion, aRequiredGenerator );
160
161 if( !aParseError.Problem().IsEmpty() )
162 problem += wxS( "\n\n" ) + _( "Full error text:" ) + wxS( "\n" ) +
163 aParseError.Problem();
164 }
165
166 lineNumber = aParseError.lineNumber;
167 byteIndex = aParseError.byteIndex;
168 inputLine = aParseError.inputLine;
169}
IO_CANCELLED(const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber, const wxString &aProblem=wxEmptyString)
Normally thrown via the macro THROW_IO_CANCELLED(), which supplies the call-site file,...
void init(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber)
virtual const wxString What() const
A composite of Problem() and Where()
IO_ERROR(const wxString &aProblem, const char *aThrowersFile, const char *aThrowersFunction, int aThrowersLineNumber)
Use macro THROW_IO_ERROR() to wrap a call to this constructor at the call site.
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)