pattern_except.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. *
  3. * Copyright (c) 1998-2002
  4. * John Maddock
  5. *
  6. * Use, modification and distribution are subject to the
  7. * Boost Software License, Version 1.0. (See accompanying file
  8. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. *
  10. */
  11. /*
  12. * LOCATION: see http://www.boost.org for most recent version.
  13. * FILE pattern_except.hpp
  14. * VERSION see <boost/version.hpp>
  15. * DESCRIPTION: Declares pattern-matching exception classes.
  16. */
  17. #ifndef BOOST_RE_V5_PAT_EXCEPT_HPP
  18. #define BOOST_RE_V5_PAT_EXCEPT_HPP
  19. #ifndef BOOST_REGEX_CONFIG_HPP
  20. #include <boost/regex/config.hpp>
  21. #endif
  22. #include <cstddef>
  23. #include <stdexcept>
  24. #include <boost/regex/v5/error_type.hpp>
  25. #include <boost/regex/v5/regex_traits_defaults.hpp>
  26. namespace boost{
  27. #ifdef BOOST_REGEX_MSVC
  28. #pragma warning(push)
  29. #pragma warning(disable : 4275)
  30. #if BOOST_REGEX_MSVC >= 1800
  31. #pragma warning(disable : 26812 4459)
  32. #endif
  33. #endif
  34. class regex_error : public std::runtime_error
  35. {
  36. public:
  37. explicit regex_error(const std::string& s, regex_constants::error_type err = regex_constants::error_unknown, std::ptrdiff_t pos = 0)
  38. : std::runtime_error(s)
  39. , m_error_code(err)
  40. , m_position(pos)
  41. {
  42. }
  43. explicit regex_error(regex_constants::error_type err)
  44. : std::runtime_error(::boost::BOOST_REGEX_DETAIL_NS::get_default_error_string(err))
  45. , m_error_code(err)
  46. , m_position(0)
  47. {
  48. }
  49. ~regex_error() noexcept override {}
  50. regex_constants::error_type code()const
  51. { return m_error_code; }
  52. std::ptrdiff_t position()const
  53. { return m_position; }
  54. void raise()const
  55. {
  56. #ifndef BOOST_NO_EXCEPTIONS
  57. #ifndef BOOST_REGEX_STANDALONE
  58. ::boost::throw_exception(*this);
  59. #else
  60. throw* this;
  61. #endif
  62. #endif
  63. }
  64. private:
  65. regex_constants::error_type m_error_code;
  66. std::ptrdiff_t m_position;
  67. };
  68. typedef regex_error bad_pattern;
  69. typedef regex_error bad_expression;
  70. namespace BOOST_REGEX_DETAIL_NS{
  71. inline void raise_runtime_error(const std::runtime_error& ex)
  72. {
  73. #ifndef BOOST_REGEX_STANDALONE
  74. ::boost::throw_exception(ex);
  75. #else
  76. throw ex;
  77. #endif
  78. }
  79. template <class traits>
  80. void raise_error(const traits& t, regex_constants::error_type code)
  81. {
  82. (void)t; // warning suppression
  83. std::runtime_error e(t.error_string(code));
  84. ::boost::BOOST_REGEX_DETAIL_NS::raise_runtime_error(e);
  85. }
  86. }
  87. #ifdef BOOST_REGEX_MSVC
  88. #pragma warning(pop)
  89. #endif
  90. } // namespace boost
  91. #endif