exception.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Boost.Geometry
  2. // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2017, 2018.
  4. // Modifications copyright (c) 2017-2018, Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_PROJECTIONS_EXCEPTION_HPP
  10. #define BOOST_GEOMETRY_PROJECTIONS_EXCEPTION_HPP
  11. #include <boost/geometry/core/exception.hpp>
  12. #include <boost/geometry/srs/projections/impl/pj_strerrno.hpp>
  13. #include <boost/throw_exception.hpp>
  14. namespace boost { namespace geometry
  15. {
  16. // TODO: make more for forward/inverse/init/setup
  17. class projection_exception : public geometry::exception
  18. {
  19. public:
  20. explicit projection_exception(int code = 0)
  21. : m_code(code)
  22. , m_msg(projections::detail::pj_strerrno(code))
  23. {}
  24. explicit projection_exception(std::string const& msg)
  25. : m_code(0)
  26. , m_msg(msg)
  27. {}
  28. projection_exception(int code, std::string const& msg)
  29. : m_code(code)
  30. , m_msg(msg)
  31. {}
  32. virtual char const* what() const throw()
  33. {
  34. //return "Boost.Geometry Projection exception";
  35. return m_msg.what();
  36. }
  37. int code() const { return m_code; }
  38. private :
  39. int m_code;
  40. std::runtime_error m_msg;
  41. };
  42. struct projection_not_named_exception
  43. : projection_exception
  44. {
  45. projection_not_named_exception()
  46. : projection_exception(projections::detail::error_proj_not_named)
  47. {}
  48. };
  49. struct projection_unknown_id_exception
  50. : projection_exception
  51. {
  52. projection_unknown_id_exception()
  53. : projection_exception(projections::detail::error_unknown_projection_id,
  54. msg())
  55. {}
  56. projection_unknown_id_exception(std::string const& proj_name)
  57. : projection_exception(projections::detail::error_unknown_projection_id,
  58. msg(proj_name))
  59. {}
  60. private:
  61. static std::string msg()
  62. {
  63. using namespace projections::detail;
  64. return pj_strerrno(error_unknown_projection_id);
  65. }
  66. static std::string msg(std::string const& proj_name)
  67. {
  68. using namespace projections::detail;
  69. return pj_strerrno(error_unknown_projection_id) + " (" + proj_name + ")";
  70. }
  71. };
  72. struct projection_not_invertible_exception
  73. : projection_exception
  74. {
  75. // NOTE: There is no error code in proj4 which could be used here
  76. // Proj4 sets points as invalid (HUGE_VAL) and last errno to EINVAL
  77. // in pj_inv() if inverse projection is not available.
  78. projection_not_invertible_exception(std::string const& proj_name)
  79. : projection_exception(projections::detail::error_non_conv_inv_meri_dist,
  80. msg(proj_name))
  81. {}
  82. private:
  83. static std::string msg(std::string const& proj_name)
  84. {
  85. return std::string("projection (") + proj_name + ") is not invertible";
  86. }
  87. };
  88. }} // namespace boost::geometry
  89. #endif // BOOST_GEOMETRY_PROJECTIONS_EXCEPTION_HPP