pattern_except.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_V4_PAT_EXCEPT_HPP
  18. #define BOOST_RE_V4_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/v4/error_type.hpp>
  25. #include <boost/regex/v4/regex_traits_defaults.hpp>
  26. namespace boost{
  27. #ifdef BOOST_MSVC
  28. #pragma warning(push)
  29. #pragma warning(disable: 4103)
  30. #endif
  31. #ifdef BOOST_HAS_ABI_HEADERS
  32. # include BOOST_ABI_PREFIX
  33. #endif
  34. #ifdef BOOST_MSVC
  35. #pragma warning(pop)
  36. #endif
  37. #ifdef BOOST_MSVC
  38. #pragma warning(push)
  39. #pragma warning(disable : 4275)
  40. #if BOOST_MSVC >= 1800
  41. #pragma warning(disable : 26812)
  42. #endif
  43. #endif
  44. class regex_error : public std::runtime_error
  45. {
  46. public:
  47. explicit regex_error(const std::string& s, regex_constants::error_type err = regex_constants::error_unknown, std::ptrdiff_t pos = 0)
  48. : std::runtime_error(s)
  49. , m_error_code(err)
  50. , m_position(pos)
  51. {
  52. }
  53. explicit regex_error(regex_constants::error_type err)
  54. : std::runtime_error(::boost::BOOST_REGEX_DETAIL_NS::get_default_error_string(err))
  55. , m_error_code(err)
  56. , m_position(0)
  57. {
  58. }
  59. ~regex_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {}
  60. regex_constants::error_type code()const
  61. { return m_error_code; }
  62. std::ptrdiff_t position()const
  63. { return m_position; }
  64. void raise()const
  65. {
  66. #ifndef BOOST_NO_EXCEPTIONS
  67. #ifndef BOOST_REGEX_STANDALONE
  68. ::boost::throw_exception(*this);
  69. #else
  70. throw* this;
  71. #endif
  72. #endif
  73. }
  74. private:
  75. regex_constants::error_type m_error_code;
  76. std::ptrdiff_t m_position;
  77. };
  78. typedef regex_error bad_pattern;
  79. typedef regex_error bad_expression;
  80. namespace BOOST_REGEX_DETAIL_NS{
  81. inline void BOOST_REGEX_CALL raise_runtime_error(const std::runtime_error& ex)
  82. {
  83. #ifndef BOOST_REGEX_STANDALONE
  84. ::boost::throw_exception(ex);
  85. #else
  86. throw ex;
  87. #endif
  88. }
  89. template <class traits>
  90. void raise_error(const traits& t, regex_constants::error_type code)
  91. {
  92. (void)t; // warning suppression
  93. std::runtime_error e(t.error_string(code));
  94. ::boost::BOOST_REGEX_DETAIL_NS::raise_runtime_error(e);
  95. }
  96. }
  97. #ifdef BOOST_MSVC
  98. #pragma warning(pop)
  99. #endif
  100. #ifdef BOOST_MSVC
  101. #pragma warning(push)
  102. #pragma warning(disable: 4103)
  103. #endif
  104. #ifdef BOOST_HAS_ABI_HEADERS
  105. # include BOOST_ABI_SUFFIX
  106. #endif
  107. #ifdef BOOST_MSVC
  108. #pragma warning(pop)
  109. #endif
  110. } // namespace boost
  111. #endif