75 lines
2.4 KiB

  1. //==============================================================================
  2. //
  3. // Copyright (c) 2015-
  4. // Authors:
  5. // * Joachim Klein <klein@tcs.inf.tu-dresden.de>
  6. // * David Mueller <david.mueller@tcs.inf.tu-dresden.de>
  7. //
  8. //------------------------------------------------------------------------------
  9. //
  10. // This file is part of the cpphoafparser library,
  11. // http://automata.tools/hoa/cpphoafparser/
  12. //
  13. // The cpphoafparser library is free software; you can redistribute it and/or
  14. // modify it under the terms of the GNU Lesser General Public
  15. // License as published by the Free Software Foundation; either
  16. // version 2.1 of the License, or (at your option) any later version.
  17. //
  18. // The cpphoafparser library is distributed in the hope that it will be useful,
  19. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. // Lesser General Public License for more details.
  22. //
  23. // You should have received a copy of the GNU Lesser General Public
  24. // License along with this library; if not, write to the Free Software
  25. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. //
  27. //==============================================================================
  28. #ifndef CPPHOAFPARSER_HOAPARSEREXCEPTION_H
  29. #define CPPHOAFPARSER_HOAPARSEREXCEPTION_H
  30. #include <stdexcept>
  31. #include <cassert>
  32. namespace cpphoafparser {
  33. /** Exception thrown to indicate an error during parsing, mostly for syntax errors. */
  34. class HOAParserException : public std::runtime_error {
  35. public:
  36. /** Constructor for simple error message. */
  37. HOAParserException(const std::string& what) :
  38. std::runtime_error(what), hasLocation(false), line(0), col(0) {}
  39. /** Constructor for error message with location (line/column) information. */
  40. HOAParserException(const std::string& what, int line, int col) :
  41. std::runtime_error(what), hasLocation(true), line(line), col(col) {}
  42. bool getHasLocation() const {
  43. return hasLocation;
  44. }
  45. /** @pre getHasLocation returns true */
  46. bool getLine() const {
  47. assert(getHasLocation());
  48. return line;
  49. }
  50. /** @pre getHasLocation returns true */
  51. bool getCol() const {
  52. assert(getHasLocation());
  53. return col;
  54. }
  55. private:
  56. /** True if we have location information */
  57. bool hasLocation;
  58. /** The line number */
  59. unsigned int line;
  60. /** The column number */
  61. unsigned int col;
  62. };
  63. }
  64. #endif