exception.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2025 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2015, 2017.
  6. // Modifications copyright (c) 2015-2017 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_CORE_EXCEPTION_HPP
  14. #define BOOST_GEOMETRY_CORE_EXCEPTION_HPP
  15. #include <exception>
  16. #include <string>
  17. namespace boost { namespace geometry
  18. {
  19. /*!
  20. \brief Base exception class for Boost.Geometry algorithms
  21. \ingroup core
  22. \details This class is never thrown. All exceptions thrown in Boost.Geometry
  23. are derived from exception, so it might be convenient to catch it.
  24. */
  25. class exception : public std::exception
  26. {
  27. public:
  28. char const* what() const noexcept override
  29. {
  30. return "Boost.Geometry exception";
  31. }
  32. };
  33. /*!
  34. \brief Invalid Input Exception
  35. \ingroup core
  36. \details The invalid_input_exception is thrown if an invalid attribute
  37. is passed into a function, e.g. a DE-9IM mask string code containing
  38. invalid characters passed into a de9im::mask constructor.
  39. */
  40. class invalid_input_exception : public geometry::exception
  41. {
  42. public:
  43. inline invalid_input_exception() {}
  44. char const* what() const noexcept override
  45. {
  46. return "Boost.Geometry Invalid-Input exception";
  47. }
  48. };
  49. /*!
  50. \brief Empty Input Exception
  51. \ingroup core
  52. \details The empty_input_exception is thrown if free functions, e.g. distance,
  53. are called with empty geometries, e.g. a linestring
  54. without points, a polygon without points, an empty multi-geometry.
  55. \qbk{
  56. [heading See also]
  57. \* [link geometry.reference.algorithms.area the area function]
  58. \* [link geometry.reference.algorithms.distance the distance function]
  59. \* [link geometry.reference.algorithms.length the length function]
  60. }
  61. */
  62. class empty_input_exception : public geometry::invalid_input_exception
  63. {
  64. public:
  65. inline empty_input_exception() {}
  66. virtual char const* what() const noexcept
  67. {
  68. return "Boost.Geometry Empty-Input exception";
  69. }
  70. };
  71. /*!
  72. \brief Invalid Output Exception
  73. \ingroup core
  74. \details The invalid_output_exception is thrown if valid output cannot be
  75. generated by a function even if arguments are valid, e.g. union of
  76. geographic polygons covering more than half of the area of the globe.
  77. */
  78. class invalid_output_exception : public geometry::exception
  79. {
  80. public:
  81. inline invalid_output_exception() {}
  82. char const* what() const noexcept override
  83. {
  84. return "Boost.Geometry Invalid-Output exception";
  85. }
  86. };
  87. /*!
  88. \brief Logic Exception
  89. \ingroup core
  90. \details Defines a type of object to be thrown as exception.
  91. It reports errors that are a consequence of faulty logic within the program
  92. such as violating logical preconditions or class invariants and may be preventable.
  93. */
  94. class logic_exception : public geometry::exception
  95. {
  96. public:
  97. inline logic_exception(char const* description)
  98. : m_description(description) {}
  99. char const* what() const noexcept override
  100. {
  101. return m_description.c_str();
  102. }
  103. private:
  104. std::string m_description;
  105. };
  106. }} // namespace boost::geometry
  107. #endif // BOOST_GEOMETRY_CORE_EXCEPTION_HPP