pattern_except.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #ifndef BOOST_REGEX_AS_MODULE
  23. #include <cstddef>
  24. #include <stdexcept>
  25. #endif
  26. #include <boost/regex/v5/error_type.hpp>
  27. #include <boost/regex/v5/regex_traits_defaults.hpp>
  28. namespace boost{
  29. #ifdef BOOST_REGEX_MSVC
  30. #pragma warning(push)
  31. #pragma warning(disable : 4275)
  32. #if BOOST_REGEX_MSVC >= 1800
  33. #pragma warning(disable : 26812 4459)
  34. #endif
  35. #endif
  36. BOOST_REGEX_MODULE_EXPORT class regex_error : public std::runtime_error
  37. {
  38. public:
  39. explicit regex_error(const std::string& s, regex_constants::error_type err = regex_constants::error_unknown, std::ptrdiff_t pos = 0)
  40. : std::runtime_error(s)
  41. , m_error_code(err)
  42. , m_position(pos)
  43. {
  44. }
  45. explicit regex_error(regex_constants::error_type err)
  46. : std::runtime_error(::boost::BOOST_REGEX_DETAIL_NS::get_default_error_string(err))
  47. , m_error_code(err)
  48. , m_position(0)
  49. {
  50. }
  51. ~regex_error() noexcept override = default;
  52. regex_constants::error_type code()const
  53. { return m_error_code; }
  54. std::ptrdiff_t position()const
  55. { return m_position; }
  56. void raise()const
  57. {
  58. #ifndef BOOST_NO_EXCEPTIONS
  59. #ifndef BOOST_REGEX_STANDALONE
  60. ::boost::throw_exception(*this);
  61. #else
  62. throw* this;
  63. #endif
  64. #endif
  65. }
  66. private:
  67. regex_constants::error_type m_error_code;
  68. std::ptrdiff_t m_position;
  69. };
  70. BOOST_REGEX_MODULE_EXPORT typedef regex_error bad_pattern;
  71. BOOST_REGEX_MODULE_EXPORT typedef regex_error bad_expression;
  72. namespace BOOST_REGEX_DETAIL_NS{
  73. template <class E>
  74. inline void raise_runtime_error(const E& ex)
  75. {
  76. #ifndef BOOST_REGEX_STANDALONE
  77. ::boost::throw_exception(ex);
  78. #else
  79. throw ex;
  80. #endif
  81. }
  82. template <class traits>
  83. void raise_error(const traits& t, regex_constants::error_type code)
  84. {
  85. (void)t; // warning suppression
  86. regex_error e(t.error_string(code), code, 0);
  87. ::boost::BOOST_REGEX_DETAIL_NS::raise_runtime_error(e);
  88. }
  89. }
  90. #ifdef BOOST_REGEX_MSVC
  91. #pragma warning(pop)
  92. #endif
  93. } // namespace boost
  94. #endif