2016-09-14 22:36:45 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007-2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
|
2020-12-19 16:00:52 +00:00
|
|
|
* Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-09-14 22:36:45 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KI_EXCEPTION_H_
|
|
|
|
#define KI_EXCEPTION_H_
|
|
|
|
|
2023-10-02 22:16:17 +00:00
|
|
|
#include <kicommon.h>
|
2016-09-14 22:36:45 +00:00
|
|
|
#include <wx/string.h>
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup exception_types
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/// macro which captures the "call site" values of __FILE_, __FUNCTION__ & __LINE__
|
|
|
|
#define THROW_IO_ERROR( msg ) throw IO_ERROR( msg, __FILE__, __FUNCTION__, __LINE__ )
|
|
|
|
|
2018-06-05 11:26:37 +00:00
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* Hold a translatable error message and may be used when throwing exceptions containing a
|
|
|
|
* translated error message.
|
2018-06-05 11:26:37 +00:00
|
|
|
*/
|
2023-10-02 22:16:17 +00:00
|
|
|
class KICOMMON_API KI_PARAM_ERROR // similar to std::invalid_argument for instance
|
2018-06-05 11:26:37 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
KI_PARAM_ERROR( const wxString& aMessage )
|
|
|
|
{
|
|
|
|
m_message = aMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
KI_PARAM_ERROR() {}
|
|
|
|
|
|
|
|
const wxString What() const
|
|
|
|
{
|
|
|
|
return m_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~KI_PARAM_ERROR() throw () {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxString m_message;
|
|
|
|
};
|
|
|
|
|
2016-09-14 22:36:45 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* Hold an error message and may be used when throwing exceptions containing meaningful
|
|
|
|
* error messages.
|
|
|
|
*
|
2016-09-14 22:36:45 +00:00
|
|
|
* @author Dick Hollenbeck
|
|
|
|
*/
|
2023-10-02 22:16:17 +00:00
|
|
|
class KICOMMON_API IO_ERROR // : std::exception
|
2016-09-14 22:36:45 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* Use macro #THROW_IO_ERROR() to wrap a call to this constructor at the call site.
|
2016-09-14 22:36:45 +00:00
|
|
|
*
|
|
|
|
* @param aProblem is Problem() text.
|
2020-12-19 16:00:52 +00:00
|
|
|
* @param aThrowersFile is the __FILE__ preprocessor macro but generated at the source
|
|
|
|
* file of thrower.
|
2016-09-14 22:36:45 +00:00
|
|
|
* @param aThrowersFunction is the function name at the throw site.
|
2017-06-20 06:10:30 +00:00
|
|
|
* @param aThrowersLineNumber is the source code line number of the throw.
|
2016-09-14 22:36:45 +00:00
|
|
|
*/
|
|
|
|
IO_ERROR( const wxString& aProblem, const char* aThrowersFile,
|
2020-12-19 16:00:52 +00:00
|
|
|
const char* aThrowersFunction, int aThrowersLineNumber )
|
2016-09-14 22:36:45 +00:00
|
|
|
{
|
|
|
|
init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber );
|
|
|
|
}
|
|
|
|
|
|
|
|
IO_ERROR() {}
|
|
|
|
|
|
|
|
void init( const wxString& aProblem, const char* aThrowersFile,
|
2020-12-19 16:00:52 +00:00
|
|
|
const char* aThrowersFunction, int aThrowersLineNumber );
|
2016-09-14 22:36:45 +00:00
|
|
|
|
|
|
|
virtual const wxString Problem() const; ///< what was the problem?
|
|
|
|
virtual const wxString Where() const; ///< where did the Problem() occur?
|
|
|
|
|
|
|
|
virtual const wxString What() const; ///< A composite of Problem() and Where()
|
|
|
|
|
|
|
|
virtual ~IO_ERROR() throw () {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxString problem;
|
|
|
|
wxString where;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* A filename or source description, a problem input line, a line number, a byte
|
2021-06-09 19:32:58 +00:00
|
|
|
* offset, and an error message which contains the caller's report and his call
|
2020-12-19 16:00:52 +00:00
|
|
|
* site information: CPP source file, function, and line number.
|
|
|
|
*
|
2016-09-14 22:36:45 +00:00
|
|
|
* @author Dick Hollenbeck
|
|
|
|
*/
|
2023-10-02 22:16:17 +00:00
|
|
|
struct KICOMMON_API PARSE_ERROR : public IO_ERROR
|
2016-09-14 22:36:45 +00:00
|
|
|
{
|
|
|
|
int lineNumber; ///< at which line number, 1 based index.
|
|
|
|
int byteIndex; ///< at which byte offset within the line, 1 based index
|
|
|
|
|
|
|
|
/// problem line of input [say, from a LINE_READER].
|
Fix source comment/doc typos (follow-up)
Found via `codespell -q 3 -S *.po,./thirdparty -L aactual,acount,aline,alocation,alog,anormal,anumber,aother,apoints,aparent,aray,dout,einstance,modul,ot,overide,serie,te,,tesselate,tesselator,tht`
2021-07-03 22:37:31 +00:00
|
|
|
/// this is brought up in original byte format rather than wxString form, in case
|
2016-09-14 22:36:45 +00:00
|
|
|
/// there was a problem with the encoding, in which case converting to wxString is
|
|
|
|
/// not reliable in this context.
|
|
|
|
std::string inputLine;
|
|
|
|
|
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* Normally called via the macro #THROW_PARSE_ERROR so that __FILE__, __FUNCTION__,
|
|
|
|
* and __LINE__ can be captured from the call site.
|
2016-09-14 22:36:45 +00:00
|
|
|
*/
|
|
|
|
PARSE_ERROR( const wxString& aProblem, const char* aThrowersFile,
|
|
|
|
const char* aThrowersFunction, int aThrowersLineNumber,
|
2020-12-19 16:00:52 +00:00
|
|
|
const wxString& aSource, const char* aInputLine,
|
2016-09-14 22:36:45 +00:00
|
|
|
int aLineNumber, int aByteIndex ) :
|
|
|
|
IO_ERROR()
|
|
|
|
{
|
|
|
|
init( aProblem, aThrowersFile, aThrowersFunction, aThrowersLineNumber,
|
2020-12-19 16:00:52 +00:00
|
|
|
aSource, aInputLine, aLineNumber, aByteIndex );
|
2016-09-14 22:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void init( const wxString& aProblem, const char* aThrowersFile,
|
|
|
|
const char* aThrowersFunction, int aThrowersLineNumber,
|
|
|
|
const wxString& aSource, const char* aInputLine,
|
|
|
|
int aLineNumber, int aByteIndex );
|
|
|
|
|
|
|
|
~PARSE_ERROR() throw () {}
|
|
|
|
|
2020-10-15 23:38:33 +00:00
|
|
|
const wxString ParseProblem() { return parseProblem; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
PARSE_ERROR() :
|
|
|
|
IO_ERROR(),
|
|
|
|
lineNumber( 0 ),
|
|
|
|
byteIndex( 0 )
|
|
|
|
{}
|
|
|
|
|
2016-09-14 22:36:45 +00:00
|
|
|
protected:
|
2020-10-15 23:38:33 +00:00
|
|
|
wxString parseProblem;
|
2016-09-14 22:36:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-12-19 16:00:52 +00:00
|
|
|
#define THROW_PARSE_ERROR( aProblem, aSource, aInputLine, aLineNumber, aByteIndex ) \
|
|
|
|
throw PARSE_ERROR( aProblem, __FILE__, __FUNCTION__, __LINE__, aSource, aInputLine, \
|
|
|
|
aLineNumber, aByteIndex )
|
2016-09-14 22:36:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-19 16:00:52 +00:00
|
|
|
* Variant of #PARSE_ERROR indicating that a syntax or related error was likely caused
|
|
|
|
* by a file generated by a newer version of KiCad than this. This can be used to generate
|
2016-09-14 22:36:45 +00:00
|
|
|
* more informative error messages.
|
|
|
|
*/
|
2023-10-02 22:16:17 +00:00
|
|
|
struct KICOMMON_API FUTURE_FORMAT_ERROR : public PARSE_ERROR
|
2016-09-14 22:36:45 +00:00
|
|
|
{
|
|
|
|
wxString requiredVersion; ///< version or date of KiCad required to open file
|
|
|
|
|
2021-06-30 15:06:07 +00:00
|
|
|
FUTURE_FORMAT_ERROR( const wxString& aRequiredVersion );
|
2016-09-14 22:36:45 +00:00
|
|
|
FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError, const wxString& aRequiredVersion );
|
|
|
|
~FUTURE_FORMAT_ERROR() throw () {}
|
2021-06-30 15:06:07 +00:00
|
|
|
|
|
|
|
void init( const wxString& aRequiredVersion );
|
2016-09-14 22:36:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** @} exception_types */
|
|
|
|
|
|
|
|
#endif // KI_EXCEPTION_H_
|