pattern_except.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. template <class E>
  82. inline void raise_runtime_error(const E& ex)
  83. {
  84. #ifndef BOOST_REGEX_STANDALONE
  85. ::boost::throw_exception(ex);
  86. #else
  87. throw ex;
  88. #endif
  89. }
  90. template <class traits>
  91. void raise_error(const traits& t, regex_constants::error_type code)
  92. {
  93. (void)t; // warning suppression
  94. regex_error e(t.error_string(code), code, 0);
  95. ::boost::BOOST_REGEX_DETAIL_NS::raise_runtime_error(e);
  96. }
  97. }
  98. #ifdef BOOST_MSVC
  99. #pragma warning(pop)
  100. #endif
  101. #ifdef BOOST_MSVC
  102. #pragma warning(push)
  103. #pragma warning(disable: 4103)
  104. #endif
  105. #ifdef BOOST_HAS_ABI_HEADERS
  106. # include BOOST_ABI_SUFFIX
  107. #endif
  108. #ifdef BOOST_MSVC
  109. #pragma warning(pop)
  110. #endif
  111. } // namespace boost
  112. #endif