You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.0 KiB

  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 <dick@softplc.com>
  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. #include <wx/wx.h>
  25. #include <ki_exception.h>
  26. const wxString IO_ERROR::What() const
  27. {
  28. #ifdef DEBUG
  29. return wxString( "IO_ERROR: " ) + Problem() + "\n\n" + Where();
  30. #else
  31. return Problem();
  32. #endif
  33. }
  34. const wxString IO_ERROR::Where() const
  35. {
  36. return where;
  37. }
  38. const wxString IO_ERROR::Problem() const
  39. {
  40. return problem;
  41. }
  42. void IO_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
  43. const char* aThrowersFunction, int aThrowersLineNumber )
  44. {
  45. problem = aProblem;
  46. // The throwers filename is a full filename, depending on Kicad source location.
  47. // a short filename will be printed (it is better for user, the full filename has no meaning).
  48. wxString srcname = aThrowersFile;
  49. where.Printf( _( "from %s : %s() line:%d" ),
  50. srcname.AfterLast( '/' ),
  51. wxString( aThrowersFunction ),
  52. aThrowersLineNumber );
  53. }
  54. void PARSE_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
  55. const char* aThrowersFunction, int aThrowersLineNumber,
  56. const wxString& aSource, const char* aInputLine, int aLineNumber,
  57. int aByteIndex )
  58. {
  59. problem.Printf( _( "%s in \"%s\", line %d, offset %d" ),
  60. aProblem,
  61. aSource,
  62. aLineNumber,
  63. aByteIndex );
  64. inputLine = aInputLine;
  65. lineNumber = aLineNumber;
  66. byteIndex = aByteIndex;
  67. // The throwers filename is a full filename, depending on Kicad source location.
  68. // a short filename will be printed (it is better for user, the full filename has no meaning).
  69. wxString srcname = aThrowersFile;
  70. where.Printf( _( "from %s : %s() line:%d" ),
  71. srcname.AfterLast( '/' ),
  72. wxString( aThrowersFunction ),
  73. aThrowersLineNumber );
  74. }
  75. FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError,
  76. const wxString& aRequiredVersion ) :
  77. PARSE_ERROR(), requiredVersion( aRequiredVersion )
  78. {
  79. // Avoid double-printing the error message
  80. bool wrapped_same_type = !!( dynamic_cast<const FUTURE_FORMAT_ERROR *>( &aParseError ) );
  81. if( wrapped_same_type )
  82. {
  83. problem = aParseError.Problem();
  84. }
  85. else
  86. {
  87. problem.Printf( _( "KiCad was unable to open this file, as it was created with a more\n"
  88. "recent version than the one you are running.\n"
  89. "To open it you will need to upgrade KiCad to a more recent version.\n\n"
  90. "Date of KiCad version required (or newer): %s\n\n"
  91. "Full error text:\n%s" ),
  92. requiredVersion, aParseError.Problem() );
  93. }
  94. lineNumber = aParseError.lineNumber;
  95. byteIndex = aParseError.byteIndex;
  96. inputLine = aParseError.inputLine;
  97. }